SQL Flow Field Guide

IF...ELSE

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

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 Flow
DECLARE @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.