SQL Flow Field Guide

UNPIVOT

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

turns listed columns into rows (NULL values are dropped)

What changes

Input
input rowset
Output or change
rowset with name/value columns

Syntax at a glance

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

Work example

A report needs UNPIVOT 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 UNPIVOT. The output shape for UNPIVOT 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.