如何將SQL Server數據行轉換爲多列?我有以下數據如何將SQL Server行轉換爲多列?
[STOCK NO] [PN1] [PN2] [PN3] [PN4] [PN4] [PN5] [PN6] [PN7] [PN8] [PN9] [PN10] [PN11] [PN12] [Qty]
700349L 600446 201743 100208 300219 400533 100280 100218 100222 100220 100221 1
類似節目我希望看到這樣的事情
[STOCK NO] [bomRev] [bomEntry] [partId] [qty] [cmnt] [srcLoc] [dType] [lead] [lineNbr]
700349L A 1 600446 1 `TEST` TEST 0 0 1
700349L A 2 201743 1 `TEST` TEST 0 0 2
700349L A 3 100208 1 `TEST` TEST 0 0 3
700349L A 4 300219 1 `TEST` TEST 0 0 4
700349L A 5 400533 1 `TEST` TEST 0 0 5
700349L A 6 100218 1 `TEST` TEST 0 0 6
700349L A 7 100222 1 `TEST` TEST 0 0 7
700349L A 8 100220 1 `TEST` TEST 0 0 8
700349L A 9 100221 1 `TEST` TEST 0 0 9
然後我想使用select語句插入如下圖所示,但我想調換行多列
INSERT INTO [DT]([bomItem], [bomRev], [bomEntry], [partId], [qty], [cmnt],[srcLoc], [dType], [lead], [lineNbr])
SELECT
[STOCK NO], 'A', [bomEntry], [partid], [qty], 'TEST', 'TEST', '0', '0', [lineNbr]
FROM
[ST]
的可能的複製[移調/樞軸行列和總和](https://stackoverflow.com/questions/18322488/transpose-pivot-rows-to-columns-and-sum)和[SQL總計 - 樞軸列](https://stackoverflow.com/q/25293671/62576) –