WITH ORDERS
AS
(
select OrderId = 1,ProductId = 100
union select 1,158
union select 1,234
union select 2,125
union select 3,105
union select 3,101
union select 3,212
union select 3,250
)
select distinct
orderid
,REPLACE(LTRIM(REPLACE((
SELECT ' ' + CAST(ProductId as varchar)
FROM ORDERS d
WHERE d.OrderId = o.OrderId
FOR XML PATH('')
),' ','')),' ', ', ') as Products
from ORDERS o
No hay comentarios.:
Publicar un comentario