More often than not we need to check multiple expressions and take specific actions based on those expressions. This situation is handled using multiple IF...ELSE IF
statements.
In this example all the expressions are evaluated from top to bottom. As soon as an expression evaluates to true, the code inside that block is executed. If no expression is evaluated to true, nothing gets executed.
IF (1 = 1 + 1)
BEGIN
PRINT 'First If Condition'
END
ELSE IF (1 = 2)
BEGIN
PRINT 'Second If Else Block'
END
ELSE IF (1 = 3)
BEGIN
PRINT 'Third If Else Block'
END
ELSE IF (1 = 1) --<-- This is True
BEGIN
PRINT 'Last Else Block' --<-- Only this statement will be printed
END