Search code examples
mysqldatabaseinsert

mysql error on run query


This is my query in mysql (I use phpmyadmin to execute the query). but I can't execute.... can help me please?

SELECT count(*) into @cnt FROM `oie_option` WHERE `opt_name` =CONCAT('earning1391',pmonth('2015-09-09')))
if(@cnt <=0)then
INSERT INTO oie_option ('opt_name','opt_value') VALUES (CONCAT('earning1391',pmonth('2015-09-09')),1000);
end if;

And this is the error:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')

if(@cnt <=0)then insert into oie_option ('opt_name','opt_value') values(CON' at line 1

Why? Thanks


Solution

  • I declared the variable and corrected.

    DECLARE cnt INT DEFAULT 0;
     SELECT count(*) INTO cnt FROM `oie_option` WHERE `opt_name` = CONCAT( 'earning1391', pmonth (now()));