3

In my query I have an IF statement:

IF(friend.block, 'yes', 'no') 

where friend.block value is 0 or 1.. but either way its putting 'yes'.. any idea?

1
  • what is the type of friend.block? Commented Oct 12, 2009 at 12:35

3 Answers 3

7

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')
Sign up to request clarification or add additional context in comments.

Comments

3

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

1 Comment

Still doesn't explain why his if function didn't work, see: dev.mysql.com/doc/refman/5.0/en/…
0
CASE friend.block WHEN 1 THEN 'yes' WHEN 0 THEN 'no' END

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.