Myy Myy - 1 year ago 132
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;
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 Source

try use function

SELECT IF(@result = 0, 'true', '((something here))') AS message
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download