Home

Collapsible if statements should be merged

Rule description

  • Collapsible if statements should be merged

 

Non-compliant Code Example

DECLARE @Number int;  
SET @Number = 50;  
IF @Number > 100  
    IF @Number < 200      --Non compliant code (Two if condition we can be merged)
        PRINT 'The number is large.';  
ELSE   
   BEGIN  
      IF @Number < 10  
        PRINT 'The number is small.';  
      ELSE  
        PRINT 'The number is medium.';  
   END ;  
GO  

Compliant Code Example

DECLARE @Number int;  
SET @Number = 50;  
IF @Number > 100  AND @Number < 200      --Compliant code
        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
 VETSQLRULE43