Gautam Buddha Temple Varanasi,Varanasi - Buddhist Pilgrimage

Friday, April 30, 2010

Display all related data in comma separated list sql server

Concetenate the two fields and display the records with comma separated string in one field.

SELECT p_scrid,
SUBSTRING(
(
SELECT (' ,' + screen_name)
FROM tbl_SCRMst t2
WHERE t1.p_scrid = t2.p_scrid
ORDER BY
p_scrid,
screen_name
FOR XML PATH( '')
),3,1000)
FROM tbl_SCRMst t1
GROUP BY p_scrid

Thanks & Regards
Santosh

No comments:

Post a Comment