T-SQL Tutorial

T-SQL LEAD


The T-SQL LEAD function is an analytic function and is used in SQL Server database to return values from a next row in the same result. Last data value is null.

LEAD Syntax


LEAD ( scalar_expression [ ,offset ] , [ default ] )
OVER ( [ partition_by_clause ] order_by_clause )



LEAD Example


select b.*,
LEAD(b.name) OVER (ORDER BY b.price) AS NextBook
from books b;