0

I have table:

Table

I want use UNPIVOT to create table, where CategoryNames rows are columns names. So, now I can just write this as

SELECT Year, Seafood, Meat/Poultry, [...]
FROM [...] UNPIVOT(...) AS Example

but I don't want write every row manually as column name, so is any option to use

SELECT CategoryName
FROM Pods

query result to create them automatically.

For this example its only 8 row, but with bigger count this could be very helpful.

How I want my final table to look

Dale K
  • 25,246
  • 15
  • 42
  • 71
DonQnei
  • 55
  • 9
  • *"I want use UNPIVOT to create table, where CategoryNames rows are columns names"* That isn't an `UNPIVOT`, that's a `PIVOT`. `UNPIVOT` transforms columns to rows, and `PIVOT` does the opposite (via aggregation). – Thom A Jul 16 '20 at 21:16
  • https://stackoverflow.com/questions/18657214/sql-server-dynamic-pivot-over-5-columns – Umair Rasheed Jul 17 '20 at 03:59

0 Answers0