Home

Boolean checks should not be inverted

Rule description

  • Boolean checks should not be inverted

 

Non-compliant Code Example

DECLARE @Number int;  
SET @Number = 50;  
IF NOT(@Number > 100)   --Non compliant code (Boolean check is inverted)
    BEGIN
		Select * From Employee Where id < @Number;
		PRINT 'The number is less then 100.';  
	END; 
ELSE   
   BEGIN  
      IF NOT (@Number < 100)    --Non compliant code (Boolean check is inverted)
        BEGIN
			Select * From Employee Where id < @Number;
			PRINT 'The number is greater then 100.';  
		END;
   ELSE  
      PRINT 'The number is medium.';  
   END ;  
GO 

Compliant Code Example

DECLARE @Number int;  
SET @Number = 50;  
IF @Number < 100   --Compliant code
    Select * From Employee Where id < @Number;
    PRINT 'The number is less then 100.';  
ELSE   
   BEGIN  
      IF @Number > 100    --Compliant code
        Select * From Employee Where id < @Number;
        PRINT 'The number is greater then 100.';  
   ELSE  
      PRINT 'The number is medium.';  
   END ;  
GO 
Visual Expert 2020
 VETSQLRULE51