LEAD()

LEAD accesses data from a subsequent row in the same result set without the use of a self-join.

Signature

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

Parameters

  • scalar_expression — The value to be returned based on the specified offset. It's an expression of any type that returns a single (scalar) value. *scalar_expression* can't be an analytic function.
  • offset — The number of rows forward from the current row from which to obtain a value. If not specified, the default is 1. *offset* can be a column, subquery, or other expression that evaluates to a positive integer or can be implicitly converted to bigint. *offset* can't be a negative value or an analytic function.
  • default — The value to return when *offset* is beyond the scope of the partition. If a default value isn't specified, `NULL` is returned. *default* can be a column, subquery, or other expression, but it can't be an analytic function. *default* must be type-compatible with *scalar_expression*.

Examples

SELECT product, amount, LEAD(amount) OVER (ORDER BY id) AS next_amount FROM dbo.orders;
product                                  amount       next_amount
---------------------------------------- ------------ ------------
keyboard                                        49.50       219.00
monitor                                        219.00        99.00
keyboard                                        99.00        27.75
mouse                                           27.75       438.00
monitor                                        438.00        15.00
cable                                           15.00         NULL

Run against SQL Server 16.0.4265.3 on 2026-09-13. This is the output we got, not the documentation’s.

Available on

  • SQL Server 2017 and later
  • Azure SQL Database
  • Azure SQL Managed Instance
  • Azure Synapse Analytics
  • Analytics Platform System (PDW)
  • Microsoft Fabric warehouse
  • Fabric SQL database

Signature and description adapted from the Microsoft SQL documentation, used under the CC BY 4.0. SQL Server and Azure are trademarks of the Microsoft group of companies. This page is not affiliated with Microsoft.