![]() ![]() Select 'Indicator3', Indicator3 union allĭepending on your version of SQL Server you could even use CROSS APPLY with the VALUES clause: select id, entityid,įinally, if you have 150 columns to unpivot and you don't want to hard-code the entire query, then you could generate the sql statement using dynamic SQL: DECLARE AS AS NVARCHAR(MAX) Select 'Indicator2', Indicator2 union all Select 'Indicator1', Indicator1 union all You could also use CROSS APPLY with UNION ALL to convert the columns: select id, entityid, Note, the datatypes of the columns you are unpivoting must be the same so you might have to convert the datatypes prior to applying the unpivot. You can use the UNPIVOT function to convert the columns into rows: select id, entityId,įor indicatorname in (Indicator1, Indicator2, Indicator3)
0 Comments
Leave a Reply. |