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
Want to find out more?
Overview
Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All features
Get acquainted with the rich features and capabilities of the tool in less than 5 minutes.
Request a demo
If you consider employing this tool for your business, request a demo to see it in action.