|Programming in MS SQL Server 2012|
IF statement is a conditional SQL Server statement that return Boolean TRUE or FALSE result value based on defined expression. IF ... ELSE ... END statements are uses in user-defined function, stored procedure and ad-hoc queries. IF condition is TRUE, SQL Server execute nested to IF statements or execute nested to ELSE statements.
Boolean_expression is an expression that returns TRUE or FALSE. If the Boolean expression contains a SELECT statement, the SELECT statement must be enclosed in parentheses.
Sql_statement | statement_block
Sql_statement | statement_block is any Transact-SQL statement or statement grouping that defined with BEGIN ... END block.
The following example describes IF ... ELSE ... END statement.
Query Output Screen
* * * * *