Home

Jump statements should not be followed by dead code

Rule description

  • Jump statements should not be followed by dead code

 

Non-compliant Code Example

CREATE PROCEDURE checkstate @param varchar(11)  
AS  
BEGIN
IF (SELECT StateProvince FROM [Data].AdditionalContactInfo WHERE ContactID = @param) = 'WA'  
BEGIN
	Select [state]
	From StateRecord
	Where name = @param;
END

RETURN;
Print 'Checkstate procedure ends';  --Non compliant code (Print statement won't get execute, it is a dead code)
END;
GO

Compliant Code Example

CREATE PROCEDURE checkstate @param varchar(11)  
AS  
BEGIN
IF (SELECT StateProvince FROM [Data].AdditionalContactInfo WHERE ContactID = @param) = 'WA'  
BEGIN
	Select [state]
	From StateRecord
	Where name = @param;
END

Print 'Checkstate procedure ends';   --Compliant code
RETURN;
END;
GO
Visual Expert 2020
 VETSQLRULE20