The topic describes the DF110 T-SQL code analysis rule.
STYLE
Conditionally executed code is not enclosed within a BEGIN…END block.
For better readability, it is recommended to enclose the conditionally executed code within a BEGIN…END block.
Not enclosing conditionally executed code within a BEGIN…END block can lead to unintended consequences and make the code harder to read and maintain. Without the block, only the first subsequent statement is considered part of the conditional execution, potentially leading to confusion about which statements are actually being executed conditionally. Additionally, enclosing code within a BEGIN…END block enhances clarity and makes it easier to identify the scope of the conditional execution. It also ensures that multiple statements are treated as a single unit, reducing the risk of errors and improving code readability.
IF DATEPART(HOUR, GETDATE()) > 17
SELECT
'It is time to go home!'
IF DATEPART(HOUR, GETDATE()) > 17
BEGIN
SELECT
'It is time to go home!'
END