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

Concatena molte righe in un'unica stringa di testo con raggruppamento

prova questo -

SELECT DISTINCT
      fileid
    , STUFF((
        SELECT N', ' + CAST([filename] AS VARCHAR(255))
        FROM tblFile f2
        WHERE f1.fileid = f2.fileid ---- string with grouping by fileid
        FOR XML PATH (''), TYPE), 1, 2, '') AS FileNameString
FROM tblFile f1