SQLTeam.com | Weblogs | Forums

What is the reason to use BEGIN END?

Hello

What is the reason to use BEGIN END?
I understand that it denotes the beginning and end of a statement, but in which situations do you have to use it?

Thanks!

You must use a BEGIN and END in many situations - for example, a WHILE loop must have a begin/end for more than a single statement following the while, an IF must have a begin/end when more than one statement follows the IF.

IF (condition)
BEGIN
     command 1;
     command 2;
END

You also must have a BEGIN/END in a scalar or multi-statement table function.

If a single statement follows a WHILE or IF then it is optional - as well as being optional as the start/end of a stored procedure.