DF049: NULL is used in a comparison or expression.
Last modified: December 25, 2024
The topic describes the DF049 T-SQL code analysis rule.
Category
BEST PRACTICE
Message
NULL is used in a comparison or expression.
Description
Operations with the NULL literal can produce undesired results. It is recommended to use the IS [NOT] NULL or ISNULL/COALESCE function instead.
Additional information
It is important to note that operations involving the NULL literal can lead to unexpected or undesired results in SQL queries. By using the IS [NOT] NULL condition or the ISNULL/COALESCE function, you can effectively handle NULL values in your queries and ensure consistent and predictable behavior, reducing the risk of errors or unexpected outcomes.
Noncompliant code example
IF @Name = NULL
BEGIN
RAISERROR('Name is null',16,-1)
END
GO
Compliant solution
IF @Name IS NULL
BEGIN
RAISERROR('Name is null',16,-1)
END
GO
Was this page helpful?