Home
IF ... ELSEIF constructs should end with ELSE clauses
Rule description
- IF ... ELSEIF constructs should end with ELSE clauses
Non-compliant Code Example
DECLARE @Number int; SET @Number = 50; IF @Number > 100 BEGIN Select * From Employee Where id < @Number; PRINT 'The number is large.'; END ELSE IF @Number < 10 --Non compliant code (IF Else block is not ending with Else clause) Select * From Employee Where id < @Number; PRINT 'The number is small.'; GO
Compliant Code Example
DECLARE @Number int; SET @Number = 50; IF @Number > 100 BEGIN Select * From Employee Where id < @Number; PRINT 'The number is large.'; END ELSE IF @Number < 10 BEGIN Select * From Employee Where id < @Number; PRINT 'The number is small.'; END ELSE --Compliant code (IF Else block is ending with Else clause) PRINT 'The number is medium.'; GO