I came across a somewhat weird behavior with data type conversions when using ISNULL. Look at this:
PRINT CASE WHEN ISNULL('', 0) = 0 THEN 'true' ELSE 'false' END
PRINT CASE WHEN ISNULL('', 0) = '' THEN 'true' ELSE 'false' END
PRINT CASE WHEN ISNULL(NULL, 0) = '' THEN 'true' ELSE 'false' END
All of these expressions evaluate to true. But when I declare an nvarchar variable and set it to NULL, the following happens:
DECLARE @charType nvarchar; SET @charType = NULL;
PRINT CASE WHEN ISNULL(@charType, 0) = '' THEN 'true' ELSE 'false' END
This should also evaluate to true, but it evaluates to false. Why?