Home

LIKE clauses should not start with wildcard characters

Rule description

  • LIKE clauses should not start with wildcard characters

 

Non-compliant Code Example

SELECT p.FirstName, p.LastName, ph.PhoneNumber  
FROM Person.PersonPhone AS ph  
INNER JOIN Person.Person AS p  
ON ph.BusinessEntityID = p.BusinessEntityID  
WHERE ph.PhoneNumber LIKE '%415'   --Non compliant code (Like clause is starting with wild cards)
ORDER by p.LastName;

Compliant Code Example

SELECT p.FirstName, p.LastName, ph.PhoneNumber  
FROM Person.PersonPhone AS ph  
INNER JOIN Person.Person AS p  
ON ph.BusinessEntityID = p.BusinessEntityID  
WHERE ph.PhoneNumber LIKE '415%'   --Compliant code (Like clause is not starting with wild cards)
ORDER by p.LastName;
Visual Expert 2020
 VETSQLRULE32