Home

Size should be specified for varchar variables and parameters

Rule description

  • Size should be specified for varchar variables and parameters

 

Non-compliant Code Example

DECLARE @find varchar;   --Non compliant code (Variable declared as a varchar without size)
SET @find = 'Man%';   
SELECT p.LastName, p.FirstName, ph.PhoneNumber  
FROM Person.Person AS p   
JOIN Person.PersonPhone AS ph ON p.BusinessEntityID = ph.BusinessEntityID  
WHERE LastName LIKE @find;

Compliant Code Example

DECLARE @find varchar(30);   --Compliant code (Variable declared as a varchar with size)
SET @find = 'Man%';   
SELECT p.LastName, p.FirstName, ph.PhoneNumber  
FROM Person.Person AS p   
JOIN Person.PersonPhone AS ph ON p.BusinessEntityID = ph.BusinessEntityID  
WHERE LastName LIKE @find;  
Visual Expert 2020
 VETSQLRULE8