Using If within select statement.

  • Is it possible to use an If within a SQL statement?

    The sort of thing I am after is:

    Select fieldName1, fieldName2, (if fieldName3 is Null return False else return True) as fieldValue From table Where fieldName5 = 2

    Is this possible?

    Cheers,

    Julian

  • CASE WHEN fieldname3 IS NULL THEN 'False' ELSE 'True' END As fieldvalue

  • You beat me to it PW..

  • Excellent, thanks for that.

    Is it possible to return boolean values as opposed to the text values True and False?

  • Use this:

    CASE WHEN fieldname3 IS NULL THEN 0 ELSE 1 END As fieldvalue

  • Perfect, thanks.

  • The answer is "no", you cannot use an if statement in a select!

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply