0
我需要在SQL Server 2005中的查詢,以便從多行結果合併成一個單一的排顯示在SQL Server 2005中多行的結果爲單行
我擁有的數據涉及到服裝的尺寸是這樣的:
# Item No. Garment SKU In Stock
1 CUR211NA-L CUR211NA 0.00
2 CUR211NA-LB CUR211NA 10.00
3 CUR211NA-M CUR211NA 0.00
4 CUR211NA-MB CUR211NA 3.00
5 CUR211NA-S CUR211NA 0.00
6 CUR211NA-SB CUR211NA -9.00
7 CUR211NA-XL CUR211NA 0.00
8 CUR211NA-XXL CUR211NA 0.00
9 CUR211NA-YTH CUR211NA 7.00
我需要顯示在列單SKU代碼行與尺寸是這樣的:
SB MB LB YTH S M L XL XXL
CUR211NA -9 3 10 7 0 0 0 0 0
我到目前爲止這是正確顯示的數量,但將每一個項目上單行
SELECT distinct T0.[U_GarmentSKU], T0.[U_Garment_Title],
(select T0.[OnHand] from oitm t1 where T0.[U_GarmentSize] IN ('47900') and t0.itemcode=t1.itemcode) 'SB',
(select T0.[OnHand] from oitm t1 where T0.[U_GarmentSize] IN ('39600') and t0.itemcode=t1.itemcode) as 'MB',
(select T0.[OnHand] from oitm t1 where T0.[U_GarmentSize] IN ('38500') and t0.itemcode=t1.itemcode) as 'LB',
(select T0.[OnHand] from oitm t1 where T0.[U_GarmentSize] IN ('50100') and t0.itemcode=t1.itemcode) as 'YTH',
(select T0.[OnHand] from oitm t1 where T0.[U_GarmentSize] IN ('47700') and t0.itemcode=t1.itemcode) as 'S',
(select T0.[OnHand] from oitm t1 where T0.[U_GarmentSize] IN ('39400') and t0.itemcode=t1.itemcode) as 'M',
(select T0.[OnHand] from oitm t1 where T0.[U_GarmentSize] IN ('38300') and t0.itemcode=t1.itemcode) as 'L',
(select T0.[OnHand] from oitm t1 where T0.[U_GarmentSize] IN ('49200','48700') and t0.itemcode=t1.itemcode) as 'XL',
(select T0.[OnHand] from oitm t1 where T0.[U_GarmentSize] IN ('49700','49300') and t0.itemcode=t1.itemcode) as 'XXL',
(select T0.[OnHand] from oitm t1 where T0.[U_GarmentSize] IN ('49800') and t0.itemcode=t1.itemcode) as 'XXXL'
FROM OITM T0 WHERE T0.[U_GarmentSKU] like 'SUR%' and T0.[U_StkStat] = 'G'
非常感謝你們!兩個很好的答案,都做到了我所需要的。 – user3232977