SQL Flow Field Guide

GROUPING_ID

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

grouping level id

What changes

Input
GROUP BY columns
Output or change
bitmask of rolled-up columns
Return type
int

Syntax at a glance

GROUPING_ID ( <column_expression> [ , ...n ] )

Work example

Identify which grouping columns were rolled up in a subtotal row.

Pass grouping expressions in the same intended order and map the bitmask to readable labels.

Check your work GROUPING_ID is a grouping bitmask, not a row identifier.

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