DF032: A control-of-flow statement is not defined by using a statement block.

Last modified: December 25, 2024

The topic describes the DF032 T-SQL code analysis rule.

Category

BEST PRACTICE

Message

A control-of-flow statement is not defined by using a statement block.

Description

It is recommended to use the BEGIN…END keywords to enclose control-of-flow statements into a statement block.

Additional information

The nested IF-ELSE clause doesn’t need to be enclosed by the BEGIN and END keywords. However, the IF clause must be wrapped by the BEGIN and END keywords.

Noncompliant code example

IF @Var1=1 SELECT '1' AS Result ELSE SELECT '2' AS Result

Compliant solution

IF @Var1=1 BEGIN
  SELECT '1' AS Result
END ELSE BEGIN
  SELECT '2' AS Result
END