This is about a bizarre behaviour I found in Microsoft Sql Server. Please correct me if I'm wrong.
SELECT COUNT(*) FROM TABLEA
WHERE [Column1] IS NULL;
This returns 30018 rows.
CREATE VIEW VIEWB AS
SELECT * FROM TABLEA AS t1
WHERE t1.[Column1] NOT IN ('Cross/Up sell', 'Renegotiation', 'Renewal')
If I check VIEWB
, I don't find NULL
in Column1
:
SELECT COUNT(*) FROM VIEWB
WHERE [Column1] IS NULL;
This returns 0 rows.
Why? The query above excludes the 3 values, but it isn't supposed to exclude NULL. Why does Ms Sql Server behave this way? Should I have expected this? How can I fix it?
NULL
is not a value.NOT IN
andIN
, I've already knew the rules around it. It's the rules aboutALL
that trips me up, IIRC,ALL
is translated internally toMAX
, hence rules about NULLs onMAX
(nulls are discarded) applies toALL
too.. or so I thought. It turns out upon further testing on the 3 RDBMS, there's a difference, the 3 RDBMS are consistent withMAX
, but not withALL