Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Più righe in una singola riga e combinare la colonna 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

Dai un'occhiata al mio sql fiddle

Risultati

PROGRAMID   ATTRIBUTENAMES
887         Study Design,Control Groups,Primary Outcomes