Home

Conditionally executed code should be denoted by either indentation or BEGIN...END block

Rule description

  • Conditionally executed code should be denoted by either indentation or BEGIN...END block

 

Non-compliant Code Example

DECLARE @Number int;  
SET @Number = 50;  
IF @Number > 100   --Non compliant code (IF and ELSE IF statements are not denoted by either indentation or BEGIN...END block)
PRINT 'The number is large.';  
ELSE IF @Number < 10  
PRINT 'The number is small.';  
ELSE  
PRINT 'The number is medium.';  
GO

Compliant Code Example

DECLARE @Number int;  
SET @Number = 50;  
IF @Number > 100   --Compliant code (IF and ELSE IF statements are denoted by either indentation or BEGIN...END block)
   PRINT 'The number is large.';  
ELSE   
   BEGIN  
      IF @Number < 10  
      PRINT 'The number is small.';  
   ELSE  
      PRINT 'The number is medium.';  
   END ;  
GO  
Visual Expert 2020
 VETSQLRULE9