Can anybody explain why the following query is evaluating the to 'null' even though the value assigned to the @Test = NULL and it is checked against 0 in CASE?
declare @Test varchar = NULL
SELECT (CASE ISNULL(@Test, '')
WHEN 0 THEN 'null'
ELSE 'not null'
END) as 'value'
this returns 'null'
AND
declare @Test varchar = NULL
SELECT (CASE ISNULL(@Test, '')
WHEN '' THEN 'null'
ELSE 'not null'
END) as 'value'
this also returns 'null'
so evaluating ISNULL(NULL,'') to '' or 0 does not make any difference?
WHEN CAST(@Test AS INT) = 0.''against0the server has to cast it to int first, ie to 0. What are you trying to do with that code? Why not use the appropriateIS NULL, ieCASE WHEN @Test IS NULL then ... ELSE .. END?