IF...ELSE
conditional execution
What changes
- Input
- boolean condition (may contain a SELECT subquery)
- Output or change
- none
Syntax at a glance
IF boolean_expression { sql_statement | statement_block } [ ELSE { sql_statement | statement_block } ]
Work example
A controlled task needs the behavior documented for IF...ELSE before it is added to a batch.
Read the linked Microsoft syntax and test IF...ELSE with synthetic input in an isolated database. Record its scope, permissions, and error path.
Check your work IF...ELSE. The observed IF...ELSE behavior matches its written purpose and the test has no effect on permanent data or credentials.
Practice SQL
Open in SQL FlowDECLARE @Score int = 82;
IF @Score >= 50
SELECT N'pass' AS Result;
ELSE
SELECT N'review' AS Result;
Open Microsoft Learn for full syntax, permissions, and details for your version.