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