Semicolon placement with IF BEGIN-END ELSE BEGIN-END
Mikael_H
Posts: 16 Bronze 1
Hi!
I really like the formatting style options available. However, in the following IF-ELSE block the semicolon after the first END does not look so nice and I often manually remove it after applying code formatting.
Default
IF @a = 1BEGIN
PRINT 'This way';
END;
ELSE
BEGIN
PRINT 'That way';
END;
Collapsed
IF @a = 1 BEGINPRINT 'This way';
END;
ELSE BEGIN
PRINT 'That way';
END;
To me, the semicolon suggests that the IF branch is completed, and the ELSE branch is a separate statement. The semicolon placement is syntactically correct, and maybe even required in upcoming versions of SQL Server.
SQL Prompt version 10.6.0.17688
Tagged:
Best Answer
-
Dan_J Posts: 465 Silver 2Hi @Mikael_HThanks for your reply on this, my sincere apology for the delay in responding to you!I completely understand that unchecking Insert semicolons is not a good solution for you on this. I have had a further look through the SQL Prompt formatting options but unfortunately cannot find a way to achieve this. As a result, can I encourage you to raise this as a feature request via our User Voice system (https://redgate.uservoice.com/forums/94413-sql-prompt). Our development team will then review it alongside other submitted feature requests.
Answers
I hope this helps, but please don't hesitate in coming back to us again if any further assistance is required on this.
Dan Jary | Redgate Software
Have you visited our Help Center?