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

Come concatenare molte righe in una stringa in SQL Server 2008?

Prova questo -

DECLARE @temp TABLE (name NVARCHAR(50))

INSERT INTO @temp (name)
VALUES ('kim'),('lee'),('park'),('cho')

SELECT STUFF((
    SELECT ',' + name
    FROM @temp
    FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '')

Uscita -

kim,lee,park,cho