Home
Boolean checks should not be inverted
Rule description
- Boolean checks should not be inverted
Non-compliant Code Example
DECLARE @Number int= 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 equal to 100.'; END ; GO
Compliant Code Example
DECLARE @Number int= 50; IF @Number < 100 --Compliant code BEGIN Select * From Employee Where id < @Number; PRINT 'The number is less then 100.'; END; ELSE BEGIN IF @Number > 100 --Compliant code BEGIN Select * From Employee Where id < @Number; PRINT 'The number is greater then 100.'; END; ELSE PRINT 'The number is equal to 100.'; END ; GO