IF Statement [T-SQL]

Provides conditional execution of a Transact-SQL statement, as an alternative to the SAP Sybase IQ IF statement.

Quick Links:

Go to Examples

Go to Usage

Go to Standards

Go to Permissions

Syntax

 IF expression
   ... statement
   ... [ ELSEIF expression ] statement ]...

Examples

(back to top)

Usage

(back to top)

The Transact-SQL IF conditional and the ELSE conditional each control the performance of only a single SQL statement or compound statement (between the keywords BEGIN and END).

In contrast to the SAP Sybase IQ IF statement, the Transact-SQL IF statement has no THEN. The Transact-SQL version also has no ELSEIF or END IF keywords.

When comparing variables to the single value returned by a SELECT statement inside an IF statement, you must first assign the result of the SELECT to another variable.

Note: You cannot nest the IF statement.

Standards

(back to top)

  • SQL—Transact-SQL extension to ISO/ANSI SQL grammar.
  • SAP Sybase Database product—Adaptive Server supports the Transact-SQL IF statement.

Permissions

(back to top)

None