SA0038 : The comparison expression evaluates to TRUE

The topic describes the SA0038 analysis rule.

Message

The comparison expression evaluates to TRUE

Description

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

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 TRUE. 
 2-- *****************************************
 3
 4SELECT * FROM sys.objects o
 5WHERE 
 61 = 1 AND
 70 != 1 AND
 82 > 1 AND 
 92>=2 AND 
102>=1 AND
112>=2.0 AND 
122>=1.0 AND 
13object_id = [object_id]  AND 
14o.object_id = o.[object_id]  AND
15'ab' = N'ab' AND
16'ab' > N'a' AND
17'ab' >= N'a' AND 
18'ab' != N'a' AND 
19'ab' = 'ab' AND
20'ab' > 'a' AND
21'ab' >= 'a' AND 
22'ab' != 'a' AND 
23name = name AND 
24[name] = [name] AND 
25o.[name] = [o].[name] AND 
26--name >= name AND
27name IN (name,'aaa','bbb') AND 
28'a' IN ('a','b','c','d') AND
291 IN (2,4,3,1) AND
301 NOT IN (2,4,3) AND
311 NOT IN (2,4,3-2) AND
32name LIKE name AND
33Exists (SELECT 0)
34-- AND dbo.myFunction(a) = dbo.myFunction(a)   -- Only if deterministic function
35
36SELECT * FROM sys.objects
37WHERE 
38object_id = [object_id]  OR 
39sys.objects.object_id = sys.objects.[object_id]
40
41SELECT * FROM sys.objects WHERE Exists (SELECT 0 WHERE 1  = 0) 
42SELECT * FROM sys.objects WHERE NOT Exists (SELECT 0 WHERE 1 = 1)

Analysis Results

  Message Line Column
1 SA0038 : The comparison expression evaluates to TRUE. 27 5
2 SA0038 : The comparison expression evaluates to TRUE. 28 4
3 SA0038 : The comparison expression evaluates to TRUE. 29 2
4 SA0038 : The comparison expression evaluates to TRUE. 30 6
5 SA0038 : The comparison expression evaluates to TRUE. 32 5
6 SA0038 : The comparison expression evaluates to TRUE. 33 0
7 SA0038 : The comparison expression evaluates to TRUE. 6 2
8 SA0038 : The comparison expression evaluates to TRUE. 7 2
9 SA0038 : The comparison expression evaluates to TRUE. 8 2
10 SA0038 : The comparison expression evaluates to TRUE. 9 1
28 SA0038 : The comparison expression evaluates to TRUE. 39 22
29 SA0038 : The comparison expression evaluates to TRUE. 42 61
See Also

Other Resources