2

I currently do not have access to a server to test this out on, but how would I go about doing something like the following

UNPIVOT (X for XY IN (
SELECT column_name AS [XY]
    FROM Information_schema.Columns
    WHERE Table_name = XYZ AND column_name LIKE '[0-9][0-9][0-9][0-9]'
)) AS unpivotedData

i.e. is it possible to dynamically populate a list of columns to unpivot rather than statically declare them

user692898
  • 109
  • 2
  • 8

1 Answers1

1

You would need to use dynamic sql to do so. Refer to the following SO question: T-SQL Pivot? Possibility of creating table columns from row values

Community
  • 1
  • 1
Tim Lentine
  • 7,782
  • 5
  • 35
  • 40