select OrderID,ProdDetailID from A

表A :

OrderID,ProdDetailID

1             6

1             7

1             9

2              5

2             3

如:orderID=1 的列转行
select STUFF((SELECT ','+ cast(ProdDetailID as varchar(4)) FROM A  where A.OrderID=1 FOR XML PATH('')), 1, 1, '')

结果:6,7,9

04-15 11:53