String_Agg() Function in SQL Server | how to get comma separated values in sql
Channel: SS UNITECH
Date: 2021-06-05

Sql server interview video link : https://youtu.be/K7FezoaPqdo

Sccript:- 
CREATE  TABLE  StringAgg_Tbl(id int,name char(3))
INSERT INTO StringAgg_Tbl VALUES (1,'CD')
,(1,'AB')
,(2,'LM')
,(3,'BC')
,(3,'GH')
,(4,'KJ')
,(3,'AB')
 
 
SELECT id, 
    STRING_AGG (name, ',') AS data 
FROM StringAgg_Tbl
GROUP BY id; 
 
SELECT id, 
    STRING_AGG (name, ',') WITHIN GROUP (ORDER BY name ASC) AS data 
FROM StringAgg_Tbl
GROUP BY id; 
 
DROP TABLE StringAgg_Tbl




Find Us On YouTube- "Subscribe Channel to watch Database related videos"          https://www.youtube.com/channel/UCZA_5vGtSpZu86VBDdSnSag

For SQL Quiz-
https://www.youtube.com/watch?v=IaDXFyZSo7Y&list=PLNRxk1s77zfitFbrlRICVDgVodMr25mYl
 
Find Us On FaceBook-
https://www.facebook.com/SS-Unitech-187705388674384/