viernes, 8 de mayo de 2020

FILAS EN UNA SOLA COLUMNA, SQL-T
















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


RESULTADO:





No hay comentarios.:

Publicar un comentario