Often you want specified statements in your stored procedure to execute only if certain conditions are true. T-SQL contains several constructs that allow you to control the flow of your stored procedures. These include BEGIN...END, IF...ELSE, GOTO, RETURN, CASE, and WHILE. The sections that follow cover each of these constructs.
You use the IF...ELSE construct to make a decision within the stored procedure. This decision is generally based on parameters supplied to the stored procedure. The IF...ELSE construct works like this:
IF (SomeCondition) BEGIN --Execute multiple statements END
With this version of the IF...ELSE construct, certain statements execute only if the condition is true. No special statements execute ...