Click or drag to resize

SA0178 : LIKE operator is used without wildcards

The topic describes the SA0178 analysis rule.

Message

LIKE operator is used without wildcards

Description

This rule checks for LIKE operator usages without wildcard characters.

The use of LIKE without one or more wildcard characters in the pattern is probably a mistake.

Scope

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

Parameters
NameDescriptionDefault Value
IgnoreNonDMLStatements

Parameter specifies whether to ignore LIKE predicate with pattern starting with "%" when it appears inside non-DML statements.

yes

Remarks

The rule does not need Analysis Context or SQL Connection.

Categories

Design Rules, New Rules

Additional Information
Example Test Script
 1SELECT     LocationID
 2FROM       Locations
 3WHERE      Specialities LIKE 'A__les' 
 4
 5SELECT     LocationID
 6FROM       Locations
 7WHERE      Specialities LIKE 'App'
 8
 9SELECT     LocationID
10FROM       Locations
11WHERE      Specialities LIKE 'A[^p]'
12
13SELECT     LocationID
14FROM       Locations
15WHERE      Specialities LIKE 'Apples' /*IGNORE:SA0178*/
16
17
18SELECT     LocationID
19FROM       Locations /*IGNORE:SA0178(STATEMENT)*/
20WHERE      Specialities LIKE 'pples' 
21
22IF db_name() like '%za%' 
23PRINT db_name()

Analysis Results

 MessageLineColumn
1SA0178 : LIKE operator is used without wildcards.729
See Also

Other Resources