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

SQL Server :clausola GROUP BY per ottenere valori separati da virgole

prova questo:

SELECT ReportId, Email = 
    STUFF((SELECT ', ' + Email
           FROM your_table b 
           WHERE b.ReportId = a.ReportId 
          FOR XML PATH('')), 1, 2, '')
FROM your_table a
GROUP BY ReportId


Demo del violino SQL