DEV Community

[Comment from a deleted post]
Collapse
 
dmfay profile image
Dian Fay

You can check nulls with CASE WHEN (dynamic VALUES is a Postgresism, but the important part works in SQL Server too):

SELECT CASE WHEN x IS NULL THEN 'yes' ELSE 'no' END AS is_null
FROM (VALUES (true), (null)) AS a (x);

 is_null 
─────────
 no
 yes
(2 rows)

It's the CASE x WHEN ... construction that does not work, since nulls aren't equivalent to anything, even each other:

SELECT CASE x WHEN NULL THEN 'yes' ELSE 'no' END AS is_null
FROM (VALUES (true), (null)) AS a (x);

 is_null 
─────────
 no
 no
(2 rows)
Collapse
 
sqlknowitall profile image
Jared Karney • Edited

Same in SQL Server