Is there any difference between IS NULL and =NULL
= NULL
is always unknown
(this is piece of 3 state logic), but WHERE
clause treats it as false
and drops from the result set. So for NULL
you should use IS NULL
Reasons are described here: Why does NULL = NULL evaluate to false in SQL server
To add to existing answers, it depends whether you have ANSI_NULLS on or not, when using "= NULL".
-- This will print TRUE
SET ANSI_NULLS OFF;
IF NULL = NULL
PRINT 'TRUE'
ELSE
PRINT 'FALSE'
-- This will print FALSE
SET ANSI_NULLS ON;
IF NULL = NULL
PRINT 'TRUE'
ELSE
PRINT 'FALSE'