SQL Flow Field Guide

PIVOT

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

implicit GROUP BY on remaining columns, aggregate of value_column, spread by pivot_column

What changes

Input
input rowset
Output or change
rowset with one column per IN-list value

Syntax at a glance

table_source PIVOT ( aggregate_function ( value_column ) FOR pivot_column IN ( <column_list> ) ) [ AS ] table_alias

Work example

A report needs PIVOT to change whether category values appear as columns or rows.

Write the input columns and aggregate first. Check how NULL values and repeated category rows affect the result.

Check your work PIVOT. The output shape for PIVOT has the intended category columns or rows and each aggregate is accounted for.

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