SA0023 : Avoid using not equal operator (<>,!=) in the WHERE clause |
![]() |
The topic describes the SA0023 analysis rule.

Avoid using not equal operator (<>,!=) in the WHERE clause

The rule checks for usage of the not equal operator in the WHERE clause as it result table and index scans.

Consider replacing the not equal operator with equals (=) or inequality operators (>,>=,<,<=) if possible.

The rule has a Batch scope and is applied only on the SQL script.

Name | Description | Default Value |
---|---|---|
IgnoreColumnsFromTempTables |
Ignore not equal comparison of columns of a temporary table or table variable. |
yes |

The rule requires SQL Connection. If there is no connection provided, the rule will be skipped during analysis.


Performance Rules, Code Smells


SQL
1CREATE INDEX IX_Table1_value ON Table1 (value) 2 3ALTER TABLE Table1 ADD computed_value AS (CASE WHEN value = 'value1' then 1 ELSE 0 END) 4 5CREATE INDEX IX_Table1_computed_value ON Table1(computed_value) 6 7-- Not equal operatror used in the WHERE clause. 8SELECT * 9FROM Table1 t1 10WHERE t1.value <> 'value1'; 11 12-- Equal operatror used in the WHERE clause. 13SELECT * 14FROM Table1 t1 15WHERE t1.computed_value = 0 |

Message | Line | Column | |
---|---|---|---|
1 | SA0023 : Avoid using not equal operator (<>,!=) in the WHERE clause. | 10 | 15 |
