I have a table with many columns like:
Table A:
ColumnA | ColumnB | ColumnC | ColumnD | ColumnE
_______________________________________________
valueA | valueB | valueC | valueD | valueE
How can I insert into Table B like below?
Table B:
ColumnName | ColumnValue
_________________________
ColumnA | valueA
ColumnB | valueB
ColumnC | valueC
ColumnD | valueD
ColumnE | valueE
Thank you!
4条答案
按热度按时间0ve6wy6x1#
You need to
Unpivot
the data. One option usesCROSS APPLY
andtable valued constructor
rqqzpn5f2#
You can also use a normal UNPIVOT for this.
A example using table variables:
Returns:
busg9geu3#
Try with dynamic UNPIVOT:
5vf7fwbs4#
Use UNPIVOT: