SQL Flow Field Guide

OVER ... ROWS / RANGE frame

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

ROWS (physical offsets) or RANGE (logical peers) frame bounds

What changes

Input
ordered partition rows
Output or change
frame per row

Syntax at a glance

{ ROWS | RANGE } { UNBOUNDED PRECEDING | n PRECEDING | CURRENT ROW | BETWEEN <frame_bound> AND <frame_bound> }

Work example

A report needs OVER ... ROWS / RANGE frame to calculate a row-aware value without collapsing detail rows.

Choose PARTITION BY, ORDER BY, and a frame explicitly. Compare the first and last row in each partition.

Check your work OVER ... ROWS / RANGE frame. The output keeps the input row count and each OVER ... ROWS / RANGE frame value matches its partition and frame.

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