DF049: NULL is used in a comparison or expression.

Last modified: May 28, 2025

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