tags:

views:

73

answers:

2

I'm running mysql 5.0 and have created a trigger. Roughly as follows:

SET @temp =(SELECT STATEMENT);

IF(@temp = 'true') THEN 
  -code block 1-
ELSE
  -code block 2-
END IF;

When I run my select statement alone it returns 'true' however in the code above 'code block 2' is being executed. Any idea why?

A: 

If your select statement is returning a boolean value then this should work:

SET @temp =(SELECT STATEMENT);

IF(@temp = true) THEN 
  -code block 1-
ELSE
  -code block 2-
END IF;
thetaiko
A: 

It looks like @temp contains way more than 'true'. Without any additional information, this seems it should be re-written so you aren't searching through strings. However, this may be what you are looking for (if 'true' is in the return string):

IF (INSTR(@temp, 'true') > 0) THEN
   -code block 1-
ELSE
   -code block 2-
END IF
37Stars