This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Check the below input data and expected output and get the list of distinct concat string values.
Input Data:
1 2 3 4 5 6 7 8 9 10 11 |
id strname ----------- ------------ 1 abc 2 xyz 3 abc 4 pqr 5 pqr 6 xyz 7 wre 8 abc 9 wre |
Expected Output:
1 2 3 |
result ----------------------- abc, pqr, wre, xyz, |
Create a table with sample data:
1 2 3 4 5 6 7 8 |
CREATE TABLE tbl_strings (id int, strname varchar(50)) GO INSERT INTO tbl_strings VALUES (1,'abc'),(2,'xyz'),(3,'abc') ,(4,'pqr'),(5,'pqr'),(6,'xyz') ,(7,'wre'),(8,'abc'),(9,'wre') GO |
Solution using XML PATH:
1 2 3 |
SELECT DISTINCT strname + ', ' FROM tbl_strings FOR XML PATH('') |
Please try the different solution for this puzzle and share it via comment...