# SQL Server Rule: SRD0011
| | |
|----|----|
| Assembly | SqlServer.Rules |
| Namespace | SqlServer.Rules.Design |
| Class | EqualityCompareWithNULLRule |
## Rule Information
| | |
|----|----|
| Id | SRD0011 |
| Friendly Name | Equality Compare With NULL Rule |
| Category | Design |
| Ignorable | false |
| Applicable Types | Procedure |
| | Scalar Function |
| | Table Valued Function |
| | View |
## Description
Equality and inequality comparisons involving a NULL constant found. Use IS NULL or IS NOT NULL.
## Summary
Equality and inequality comparisons involving a NULL constant found. Use IS NULL or IS NOT NULL.
### Examples
```sql
Create table dbo.EqualsNull
(
ID1 integer not null
)
go
Create Procedure dbo.EqualsNullTest
AS
BEGIN
SET NOCOUNT ON
Select ID1 from dbo.EqualsNull where ID1 =NULL
END
-- SML046, SRD0011
```
### Remarks
This rule scans stored procedures, views, functions and triggers to flag use of equality
and inequality comparisons involving a NULL constant. These comparisons are undefined when
<c>ANSI_NULLS</c> option is set to ON. It is recommended to set <c>ANSI_NULLS</c> to ON and
use the <c>IS</c> keyword to compare against NULL constants. Care must be taken when
comparing null values. The behavior of the comparison depends on the setting of the
<c>SET ANSI_NULLS</c> option. When <c>SET ANSI_NULLS</c> is ON, a comparison in which one
or more of the expressions is NULL does not yield either TRUE or FALSE; it yields UNKNOWN.
This is because a value that is unknown cannot be compared logically against any other value.
This occurs if either an expression is compared to the literal NULL, or if two expressions
are compared and one of them evaluates to NULL.
<sub><sup>Generated by a tool</sup></sub>