I have a table with following data
First Second Third Fourth Fifth Sixth
2013-08-20 2013-08-21 2013-08-22 2013-08-23 2013-08-24 2013-08-25
And using UNPIVOT
SELECT Data
,DATENAME(DW, Data) AS DayName
FROM Cal
UNPIVOT(Data FOR D IN (
First,
Second,
Third,
Fourth,
Fifth,
Sixth )) AS unpvt
I get the following result
Data DayName
2013-08-20 Tuesday
2013-08-21 Wednesday
2013-08-22 Thursday
2013-08-23 Friday
2013-08-24 Saturday
2013-08-25 Sunday
Now my question is can we pass column names dynamically to the UNPIVOT
so that when the columns in the table increases we may not have to alter the statement.