SQL Flow Field Guide

LEAD

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

window analytic

What changes

Input
ordered rows of the partition (frame for FIRST_VALUE/LAST_VALUE; offset rows for LAG/LEAD)
Output or change
one value per row
Return type
The data type of the specified scalar_expression. NULL is returned if scalar_expression is nullable or default is set to NULL. LEAD is nondeterministic. For more information, see Deterministic and Non

Syntax at a glance

LEAD ( scalar_expression [ , offset ] [ , default ] ) [ IGNORE NULLS | RESPECT NULLS ] OVER ( [ partition_by_clause ] order_by_clause )

Work example

Compare a row with the next value in an ordered sequence.

Check the final row and use a default only when it has a clear business meaning.

Check your work LEAD follows the window order, not the order rows happen to arrive.

Practice SQL

Open in SQL Flow
SELECT n, LEAD(n) OVER (ORDER BY n) AS next_n FROM (VALUES (10), (20), (30)) AS v(n);

Open Microsoft Learn for full syntax, permissions, and details for your version.