Conditionally execute T-SQL statements.

      IF boolean_expression
{ sql_statement | statement_block } [ ELSE { sql_statement | statement_block } ] Key boolean_expression An expression that returns TRUE or FALSE. If Boolean_expression contains a SELECT statement, it must be enclosed in parentheses. sql_statement | statement_block Any T-SQL statement or statement grouping as defined with a statement block. Unless a statement block is used, the IF or ELSE condition can affect the performance of only one T-SQL statement. Use BEGIN and END to define a statement block.


IF exists (select *
from sales
where customer_id = 123)
Print 'Record exits'
Print 'Record doesn''t exist'

“IF you can keep your head when all about you, Are losing theirs and blaming it on you...” ~ Rudyard Kipling 1899

Related commands

Equivalent Oracle command: Select into a cursor then: IF cursorname = 123 Then...

Copyright © 1999-2023 SS64.com
Some rights reserved