How to concat many rows into one strings?
Query:
SELECT name FROM mytable;
Result:
name
----
kim
lee
park
cho
Just I want.
name
----
kim,lee,park,cho
Impossible?
To sum rows with same ID, use the GROUP BY HAVING clause.
Try this one -
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, '')
Output -
kim,lee,park,cho
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With