Myy Myy - 2 months ago 7
MySQL Question

mySQL If statement

I'm trying to make this If Statement work, but I can't seem to make it do what I want. if I do a select @result, It'll give me the value 0, then why doesn't the IF statement work?

SET @message = '((sometihng here))';
select LEFT(@message, 1) into @firstChar;
select STRCMP(@firstChar,'(') into @result;
IF (@result = 0) THEN
SET @message = 'true';
//more selects and cals here;
END IF;
select @message;


I should get true, but I don't it shows me an error:


SQL query: IF( @result =0 ) THEN SET @message = 'true'; MySQL said:

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 (@result = 0) THEN SET @message = 'true'' at line 1

Answer

try use function http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_if

SELECT IF(@result = 0, 'true', '((something here))') AS message