Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Understanding IF BEGIN END
Message
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
Other
Title:
Understanding IF BEGIN END
Miscellaneous
Thread ID:
01553972
Message ID:
01553972
Views:
99
Hi,

I want to be sure I understand the use of BEGIN / END with IF statement in a stored procedure.

Here is how I understand it:

1. If there is only one statement after the IF condition, I don't need to have BEGIN / END. That is, this one statement after IF will be executed.

2. But if there is more than one statement after IF, I must have these statements enclosed with BEGIN / END? Here is an example:
if @SomeVar = 1
   BEGIN
   select @FoundValue = column_name from table1 where 'some condition'
   if len(rtrim(@FoundValue)) > 0
      set @Var2 = @FoundValue
   END
That is, I must have the BEGIN and END above to make sure all lines after the first IF are executed only if @SomeVar =1 ?
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Next
Reply
Map
View

Click here to load this message in the networking platform