I saw this example in a presentation lately. When you run a query like this:
SELECT COUNT(NULL)
You get the following error:
Operand data type NULL is invalid for count operator.
When you run this:
SELECT COUNT(1/NULL)
You get 0 as a result, even though the division itself yields NULL as a result. Same happens if you swap the 1 and NULL.
But if you do this:
SELECT COUNT(NULL/NULL)
You get the same error as the first query again (the division itself is legit, yields NULL).
Can anyone explain how sql server works to give these kind of results?