views:

152

answers:

4

in my query i have IF(friend.block, 'yes', 'no') and friend.block value is 0 or 1.. but eaither way its putting 'yes'.. any idea?

A: 
CASE friend.block WHEN 1 THEN 'yes' WHEN 0 THEN 'no' END
Zed
A: 

Reference: MySQL Reference

The syntax is:

IF (friend.block = 1) THEN
    'Yes'
ELSE
    'No'
END IF

You can use case statement:

CASE friend.block WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' END

Kirtan
Still doesn't explain why his if function didn't work, see: http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_if
Andre Miller
A: 

if(friend.block > '0', 'yes', 'no') :) thanks everyone

Basit
+3  A: 

friend.block should be of type INTEGER for that to work or you have to put a comparaison there:

IF(friend.block != 0, 'yes', 'no)
najmeddine