Partilhar via


ELSE (IF...ELSE) (Transact-SQL)

Imposes conditions on the execution of a Transact-SQL statement. The Transact-SQL statement (sql_statement) following the Boolean_expressionis executed if the Boolean_expression evaluates to TRUE. The optional ELSE keyword is an alternate Transact-SQL statement that is executed when Boolean_expression evaluates to FALSE or NULL.

Topic link iconTransact-SQL Syntax Conventions

Syntax

IF Boolean_expression { sql_statement | statement_block } 
[ 
     ELSE 
     { sql_statement | statement_block } ] 

Arguments

  • 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 }
    Is any valid Transact-SQL statement or statement grouping as defined with a statement block. To define a statement block (batch), use the control-of-flow language keywords BEGIN and END. Although all Transact-SQL statements are valid within a BEGIN...END block, certain Transact-SQL statements should not be grouped together within the same batch (statement block).

Result Types

Boolean

See Also

Reference

ALTER TRIGGER (Transact-SQL)
Control-of-Flow Language (Transact-SQL)
CREATE TRIGGER (Transact-SQL)
IF...ELSE (Transact-SQL)

Other Resources

Batches

Help and Information

Getting SQL Server 2005 Assistance