HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

CASE statement with IS NULL and NOT NULL

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
casestatementwithnullandnot

Problem

Is there any better way to write the lines below in SQL Server 2005?

CASE
WHEN (ID IS NULL)
   THEN 'YES'
WHEN (ID IS NOT NULL)
   THEN 'NO'
END AS ID_Value,

Solution

Did you try:

CASE WHEN (ID IS NULL) THEN 'YES' ELSE 'NO' END AS ID_Value,


I only have access to 2008 right now, but I'd hope that this syntax would still work in 2005 (seems like something that would be part of the original definition of CASE).

Code Snippets

CASE WHEN (ID IS NULL) THEN 'YES' ELSE 'NO' END AS ID_Value,

Context

StackExchange Database Administrators Q#20678, answer score: 18

Revisions (0)

No revisions yet.