DF049: NULL is used in a comparison or expression.

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

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All Features

All features

Get acquainted with the rich features and capabilities of the Studio in less than 5 minutes.
Request a demo

Request a demo

If you consider employing the Studio for your business, request a demo to see it in action.
Ready to start using dbForge Studio for SQL Server?