I'm confused as to why these two CASE statements provide different answers, when a DATETIME value is NULL.
DECLARE @MyDate DATETIME = NULL;
SELECT CASE ISNULL(@MyDate, 0)
WHEN 0 THEN 'It Is Null'
ELSE 'It Is a Date'
END;
This results in the value 'It Is Null', which is straightforward - a NULL value is turned into 0, then we test for 0. However:
DECLARE @MyDate DATETIME = NULL;
SELECT CASE @MyDate
WHEN NULL THEN 'It Is Null'
ELSE 'It Is a Date'
END;
The above results in 'It Is a Date', which is my point of confusion. The clause will not accept "WHEN IS NULL" which is what I first thought was the problem.
Why won't CASE WHEN recognise a NULL value?