je besoin d'une requête dans SQL Server 2005 pour combiner les résultats de plusieurs lignes en une seule rangéeAfficher les résultats sur plusieurs rangées dans SQL Server 2005 comme une seule ligne
Les données que j'ai concerne la taille des vêtements comme celui-ci:
# 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
-je présenter une seule ligne de code SKU avec les tailles dans les colonnes comme ceci:
SB MB LB YTH S M L XL XXL
CUR211NA -9 3 10 7 0 0 0 0 0
ce que j'ai à ce jour qui montre correctement les quantités, mais de placer chaque élément sur une ligne séparée
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'
merci beaucoup les gars! Les deux bonnes réponses et les deux ont fait exactement ce dont j'avais besoin. – user3232977