Checking for NULL values in a CASE Statement

This is a pretty simple need, with an equally simple solution.

I was initially using the simple format of the CASE statement:

CASE input_expression
     WHEN NULL THEN result_expression
   [ ELSE else_result_expression ]
END

…which does not handle this situation.  The solution is to change it to the searched version:

Searched CASE expression:

CASE
     WHEN Boolean_expression IS NULL THEN result_expression
     [ ELSE else_result_expression ]
END

Leave a comment