SA0039 : The comparison expression evaluates to FALSE

The topic describes the SA0039 analysis rule.

Message

The comparison expression evaluates to FALSE

Description

The rule checks for comparison expressions which will always evaluate to FALSE.

Scope

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

Parameters

Rule has no parameters.

Remarks

The rule does not need Analysis Context or SQL Connection.

Categories

Design Rules, Code Smells

Additional Information

There is no additional info for this rule.

Example Test Script
SQL
 1-- Comparison will always evaluate to FALSE. 
 2-- *****************************************
 3
 4SELECT * FROM sys.objects o
 5WHERE 
 61 != 1 OR
 71>1 OR
 80 > 1 OR
 91 = 0 OR
100 != 0 OR 
112!=2 OR 
122<>2 OR 
132<1 OR 
142<=1 OR 
152<>2.0 OR 
162.0<1.0 OR 
172<=1 OR 
18
191>=2 OR 
20
21object_id != [object_id]  OR 
22o.object_id != o.[object_id]  OR
23'A'<'A' OR
24'A'!='A' OR
25'B'<>'B' OR
26'B'<>N'B' OR
27'ab' != 'ab' OR
28'ab' != N'ab' OR
29'ab' < N'a' OR
30'ab' < N'a' OR 
31'ab' = N'a' OR 
32'ab' < 'a' OR
33'ab' < 'a' OR 
34'ab' = 'a' OR 
35name != name OR
36name <> name OR
37name < name OR
38o.[name] > o.name OR
39name NOT LIKE name OR 
401 IN (2,4,3) OR 
41'a' IN ('b','c','d', 6) OR
421 NOT IN (1, 2,4,3, 2-1) OR 
431 IN (2,4,3) OR 
44'a'  NOT IN ('b','c','d','a' ) OR
45NOT Exists (SELECT 0)
46
47IF 1 > 1
48BEGIN
49    SELECT * FROM sys.objects
50    WHERE 
51    object_id != [object_id] OR 
52    sys.objects.object_id != sys.objects.[object_id] OR
53    object_id <> [object_id] OR 
54    sys.objects.object_id <> sys.objects.[object_id] OR
55    object_id > [object_id]  OR 
56    sys.objects.object_id < sys.objects.[object_id] 
57END
58
59-- NOTE:The expressions are not evaluated
60SELECT * FROM sys.objects
61WHERE
621 NOT IN (0, 2,4,3, 2 - 1) OR
63'a' IN (SELECT 1) OR
641 IN (2,4,3, 2-1)
65
66SELECT * FROM sys.objects WHERE Exists (SELECT 0 WHERE 1 = 0) 
67SELECT * FROM sys.objects WHERE NOT Exists (SELECT 0 WHERE 1 = 1)

Analysis Results

  Message Line Column
1 SA0039 : The comparison expression evaluates to FALSE. 39 9
2 SA0039 : The comparison expression evaluates to FALSE. 40 2
3 SA0039 : The comparison expression evaluates to FALSE. 41 4
4 SA0039 : The comparison expression evaluates to FALSE. 42 6
5 SA0039 : The comparison expression evaluates to FALSE. 43 2
6 SA0039 : The comparison expression evaluates to FALSE. 44 9
7 SA0039 : The comparison expression evaluates to FALSE. 45 4
8 SA0039 : The comparison expression evaluates to FALSE. 6 2
9 SA0039 : The comparison expression evaluates to FALSE. 7 1
10 SA0039 : The comparison expression evaluates to FALSE. 8 2
45 SA0039 : The comparison expression evaluates to FALSE. 56 26
46 SA0039 : The comparison expression evaluates to FALSE. 66 57
See Also

Other Resources