sql >> Base de Datos >  >> RDS >> Sqlserver

Múltiples filas en una sola fila y combinar columna SQL

select ProgramId,
stuff(
(
    select ','+ [attributename]
    from Table1 
    where programid = t.programid for XML path('')

),1,1,'') as AttributeNames
from (select distinct programid 
      from Table1 )t

Mira mi sql fiddle

Resultados

PROGRAMID   ATTRIBUTENAMES
887         Study Design,Control Groups,Primary Outcomes