The code is poorly written regardless of which version of SQL you're using, because NULL
is never "equal" to anything (even itself). It's "unknown", so whether or not it's equal (or greater than, or less than, etc.) another value is also "unknown".
One thing that can affect this behavior is the setting of ANSI_NULLS
. If your 2005 server (or that connection at least) has ANSI_NULLS
set to "OFF
" then you'll see the behavior that you have. For a stored procedure the setting is dependent at the time that the stored procedure was created. Try recreating the stored procedure with the following before it:
SET ANSI_NULLS ON
GO
and you'll likely see the same results as in 2008.
You should correct the code to properly handle NULL
values using something like:
WHERE X = @X OR (X IS NULL AND @X IS NULL)
or
WHERE X = COALESCE(@X, X)
The specifics will depend on your business requirements.