I am not getting simple Boolean algebra on my sql server. According to msdn, the following statement should return "1", but on my server it returns "0". Can you help me?
SET ANSI_NULLS ON SELECT CASE WHEN NOT(1=NULL) THEN 1 ELSE 0 END
Please see msdn . It clearly states: "Comparing NULL with a value other than NULL always results in FALSE." - regardless of the ANSI_NULLS settings. Thus, "1 = NULL" must be FALSE, and NOT (FALSE) must be TRUE, and the statement must return "1".
But on my machine, it returns "0"!
One explanation may be that "1 = NULL" evaluates to "UNKNOWN". NOT (UNKNOWN) is still UNKNOWN ( msdn ), which will force the CASE-Statement to ELSE.
But then the official documentation of the equality operator would be wrong. I can not believe this!
Can anyone explain this behavior?
Thanks so much for any help!
Edit (2012-03-15):
One thing I just found that might be of interest to some of you:
CREATE TABLE
The print statement writes "False", but the insert starts without errors. The SQL server seems to negate the check constraint for finding rows that do not check the constraints:
IF EXISTS (SELECT * FROM inserted WHERE NOT(Value>NULL)) <Generate error>
Since check-constraint evaluates to UNKNOWN, the negation is also UNKNOWN, and SqlServer does not find a string that violates the check constraint.
Andreas
source share