Why does this give me 1 which is what I was expecting:
IF (SELECT 123) = 123
PRINT 1
ELSE
PRINT 2
But this gives me 2 which I was not expecting:
IF (SELECT NULL) = NULL
PRINT 1
ELSE
PRINT 2
NULL
values are checked by IS NULL
you have to use:
IF (SELECT NULL) IS NULL
PRINT 1
ELSE
PRINT 2
from the manual:
To search for column values that are NULL, you cannot use an expr = NULL test. The following statement returns no rows, because expr = NULL is never true for any expression
If you put NULLS OFF
SET ANSI_NULLS OFF
IF (SELECT NULL) = NULL
PRINT 1
ELSE
PRINT 2
then you will get PRINT 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With