Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CASE myField WHEN NULL ... 1

Status
Not open for further replies.

jonbatts

Programmer
Apr 12, 2005
114
US
I'm trying to use a case statement to return a specific value.
Code:
CASE myField WHEN NULL THEN 'FieldIsNull' WHEN 'A' THEN 'AValue' WHEN 'B' THEN 'BValue' ELSE 'NotListed' END
Of course when myField is NULL I'm getting 'NotListed' because of the inability to compare NULL. Is there a way to do this with a comparitive SQL statement like this, or do I have to resort to
Code:
CASE WHEN myField IS NULL THEN 'FieldIsNull' WHEN myField = 'A' THEN 'AValue' WHEN myField = 'B' THEN 'BValue' ELSE 'NotListed' END
Thanks.
 
Hadn't thought of that. It would do the trick in my case. The only problem is if I wanted to allow myField to be the actual string 'NULL'. Like I said it works in my case. Thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top