Click or drag to resize

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

The topic describes the SA0023 analysis rule.

Message

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

Description

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.

Scope

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

Parameters
NameDescriptionDefault Value
RuleSuppressMark

Suppress rule reporting a rule violation in case a comment containing the value of this parameter is found close to the source of violation.

IGNORE:SA0023

Remarks

The rule does not need Analysis Context or SQL Connection.

Categories

Performance Rules

Additional Information
Example Test Script
 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

Analysis Results

 MessageLineColumn
1SA0023 : Avoid using not equal operator (<>,!=) in the WHERE clause.1015
See Also

Other Resources