When multiple lines of code follow an IF statement it is best to wrap the lines in a BEGIN. . . END block. : Code Block « Transact SQL « SQL Server / T-SQL Tutorial
20. 13. 1. When multiple lines of code follow an IF statement it is best to wrap the lines in a BEGIN. . . END block.
7>
8>
9> CREATE PROCEDURE spTableExists
10> @TableName VarChar(128)
11> AS
12> IF EXISTS(SELECT * FROM sysobjects WHERE name = @TableName)
13> BEGIN
14> PRINT @TableName + ' exists'
15> PRINT @TableName + ' exists'
16> END
17> ELSE
18> PRINT @TableName + ' does not'
19> GO
1>
2> drop proc spTableExists;
3> GO
20. 13. Code Block
20. 13. 1.
When multiple lines of code follow an IF statement it is best to wrap the lines in a BEGIN. . . END block.