Why is this an issue?
Code is clearest when each statement has its own line. Nonetheless, it is a common pattern to combine on the same line an IF
and its
resulting then statement. However, when an IF
is placed on the same line as the closing END
from a preceding
ELSE
or ELSE IF
, it is either an error - ELSE
is missing - or the invitation to a future error as maintainers
fail to understand that the two statements are unconnected.
Noncompliant code example
IF (condition1) BEGIN
EXEC something
END IF (condition2) BEGIN -- Noncompliant
EXEC something
END
Compliant solution
IF (condition1) BEGIN
EXEC something
END ELSE IF (condition2) BEGIN
EXEC something
END
Or
IF (condition1) BEGIN
EXEC something
END
IF (condition2) BEGIN
EXEC something
END