Skip to content

Commit 1c05869

Browse files
Merge pull request #36699 from mstehrani/patch-25
Saving UNPIVOT results in Fabric
2 parents b70d9b7 + 33d03c6 commit 1c05869

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

docs/t-sql/queries/from-using-pivot-and-unpivot.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Learn about the Transact-SQL PIVOT and UNPIVOT relational operators
44
author: VanMSFT
55
ms.author: vanto
66
ms.reviewer: wiassaf, randolphwest
7-
ms.date: 10/01/2024
7+
ms.date: 02/24/2026
88
ms.service: sql
99
ms.subservice: t-sql
1010
ms.topic: reference
@@ -92,15 +92,26 @@ FOR <output column for names of the pivot columns>
9292

9393
## Remarks
9494

95-
The column identifiers in the `UNPIVOT` clause follow the catalog collation.
95+
- The column identifiers in the `UNPIVOT` clause follow the catalog collation.
9696

97-
- For [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)], the collation is always `SQL_Latin1_General_CP1_CI_AS`.
97+
- For [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)], the collation is always `SQL_Latin1_General_CP1_CI_AS`.
9898

99-
- For [!INCLUDE [ssNoVersion_md](../../includes/ssnoversion-md.md)] partially contained databases, the collation is always `Latin1_General_100_CI_AS_KS_WS_SC`.
99+
- For [!INCLUDE [ssNoVersion_md](../../includes/ssnoversion-md.md)] partially contained databases, the collation is always `Latin1_General_100_CI_AS_KS_WS_SC`.
100100

101-
If the column is combined with other columns, then a collate clause (`COLLATE DATABASE_DEFAULT`) is required to avoid conflicts.
101+
- If the column is combined with other columns, then a collate clause (`COLLATE DATABASE_DEFAULT`) is required to avoid conflicts.
102102

103-
In [!INCLUDE [fabric](../../includes/fabric.md)] and [!INCLUDE [ssazuresynapse_md](../../includes/ssazuresynapse-md.md)] pools, queries with `PIVOT` operator fail if there's a `GROUP BY` on the nonpivot column output by `PIVOT`. As a workaround, remove the nonpivot column from the `GROUP BY`. Query results are the same, as this `GROUP BY` clause is a duplicate.
103+
- In [!INCLUDE [fabric](../../includes/fabric.md)] and [!INCLUDE [ssazuresynapse_md](../../includes/ssazuresynapse-md.md)] pools, queries with `PIVOT` operator fail if there's a `GROUP BY` on the nonpivot column output by `PIVOT`. As a workaround, remove the nonpivot column from the `GROUP BY`. Query results are the same, as this `GROUP BY` clause is a duplicate.
104+
105+
- Column names are of type **sysname** or **nvarchar(128)**. Because `UNPIVOT` projects column names as values, the data type for an `UNPIVOT` column will also be **nvarchar(128)**, which is not a supported data type in Fabric Data Warehouse. If you want to save the results of `UNPIVOT` to a table in a warehouse in Fabric, cast it to a [supported data type in Fabric Data Warehouse](/fabric/data-warehouse/data-types). For example:
106+
107+
```sql
108+
CREATE TABLE myTable AS
109+
SELECT value,
110+
CAST(columnNames as VARCHAR(128) ) columnNames
111+
FROM myTableToUnpivot
112+
UNPIVOT( value
113+
FOR columnNames IN( col1, col2 )) unpvt;
114+
```
104115

105116
## Basic PIVOT example
106117

0 commit comments

Comments
 (0)