Realise this is an old post, but I came across the thread as I had the same problem recently. I had previously been successful using the syntax (as some have indicated above) as:
case [sourcecolumn] when NULL then ...<alternative output>...
Example:
, CASE LOWER(EmailAddr)
WHEN NULL THEN NULL
WHEN '' THEN NULL
WHEN 'no email address' THEN NULL -- several mixed case variations
-- Source email address may also contain carriage returns!
-- REPLACE(REPLACE(@str, CHAR(13), ''), CHAR(10), '')
-- Retain original email address, but switch it to all lower case and remove any whitespaces/CR/LF chars.
ELSE LOWER(REPLACE(REPLACE(REPLACE(EmailAddr, ' ', ''), CHAR(10), ''), CHAR(13), ''))
END
But recently this has not given the expected/desired results (not sure if it's due to the source column type, it's just a Varchar).
However, I found the following syntax worked for me instead:
case When [sourcecolumn] IS Null Then ...<alternative output>...
Note that if you have a set of conditions to check for (not just Null), then you have to add the [sourcecolumn] to each conditional test line.
The re-worked example:
, CASE
WHEN LOWER(EmailAddr) IS NULL THEN NULL
WHEN LOWER(EmailAddr) = '' THEN NULL
WHEN LOWER(EmailAddr) = '#N/A' THEN NULL
WHEN LOWER(EmailAddr) = 'no email address' THEN NULL -- several mixed case variations
-- Retain original email address, but switch it to all lower case and remove any possible whitespaces/CR/LF chars.
ELSE LOWER(REPLACE(REPLACE(REPLACE(EmailAddr, ' ', ''), CHAR(10), ''), CHAR(13), ''))
END