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: