我试图找出一种方法来将[列1],[列2],[列3],[列4],[列5] 转换为单列[类型]。我也希望它有行号。因此,我希望它看起来像一个例子。此外,如果我只想要输入数据列,该怎么办?像Column1和Column2都有值,但是列3,4和5没有。在这种情况下,我只想让1和2显示在我的结果集上。如何使用行号将多列转换为单行?
现在:
[ID1]-[Column1],[Column2],[Column3],[Column4],[Column5]
[ID2]-[Column1],[Column2],[Column3],[Column4],[Column5]
愿望:
[ID1]-[Column1],[Row1]
[ID1]-[Column2],[Row2]
[ID1]-[Column3],[Row3]
[ID1]-[Column4],[Row4]
[ID1]-[Column5],[Row5]
[ID2]-[Column1],[Row1]
[ID2]-[Column2],[Row2]
Etc......
谢谢!
使用UNPIVOT声明 –
的可能的复制[如何插入行通过选择列的表名称和值从SQL Server中的另一个表](http://stackoverflow.com/questions/39763621/how-to-insert-row-into-a-table-by-select-column-name-and-value-from -otherother-tabl) –
不理解RowNumber?只是为了表明列号? –