In this example I am showing how to get comma separated string for particular filed in sqlserver. I am using sqlserevr 2008.
Table Data:
Id  Email               Name
2Â Â Â TEST@TEST.COMÂ Â Â A
2Â Â Â TEST@TEST.COMÂ Â Â B
2Â Â Â TEST@TEST.COMÂ Â Â C
2Â Â Â TEST@TEST.COMÂ Â Â D
2Â Â Â TEST@TEST.COMÂ Â Â E
1Â Â Â TEST@TEST.COMÂ Â Â A
1Â Â Â TEST@TEST.COMÂ Â Â C
1Â Â Â TEST@TEST.COMÂ Â Â D
1Â Â Â TEST@TEST.COMÂ Â Â B
1Â Â Â TEST@TEST.COMÂ Â Â D
5Â Â Â TEST@TEST.COMÂ Â Â A
5Â Â Â TEST@TEST.COMÂ Â Â C
5Â Â Â TEST@TEST.COMÂ Â Â D
5Â Â Â TEST@TEST.COMÂ Â Â B
5Â Â Â TEST@TEST.COMÂ Â Â DOutput:
1Â Â Â A,B,C,D,D
2Â Â Â A,B,C,D,E
5Â Â Â A,B,C,D,DDECLARE @TABLE TABLE(ID INT, EMAIL VARCHAR(20), NAME VARCHAR(10))
INSERT INTO @TABLE
SELECT 2   ,’TEST@TEST.COM’,   ‘A’ UNION ALL
SELECT 2   ,’TEST@TEST.COM’,   ‘B’ UNION ALL
SELECT 2   ,’TEST@TEST.COM’,   ‘C’ UNION ALL
SELECT 2   ,’TEST@TEST.COM’,   ‘D’ UNION ALL
SELECT 2   ,’TEST@TEST.COM’,   ‘E’ UNION ALL
SELECT 1   ,’TEST@TEST.COM’,   ‘A’ UNION ALL
SELECT 1   ,’TEST@TEST.COM’,   ‘C’ UNION ALL
SELECT 1   ,’TEST@TEST.COM’,   ‘D’ UNION ALL
SELECT 1   ,’TEST@TEST.COM’,   ‘B’ UNION ALL
SELECT 1   ,’TEST@TEST.COM’,   ‘D’ UNION ALL
SELECT 5   ,’TEST@TEST.COM’,   ‘A’ UNION ALL
SELECT 5   ,’TEST@TEST.COM’,   ‘C’ UNION ALL
SELECT 5   ,’TEST@TEST.COM’,   ‘D’ UNION ALL
SELECT 5   ,’TEST@TEST.COM’,   ‘B’ UNION ALL
SELECT 5   ,’TEST@TEST.COM’,   ‘D’SELECT T2.ID,
STUFF((SELECT ‘,’+T1.NAME FROM @TABLE T1 WHERE T1.ID=T2.ID ORDER BY T1.NAME FOR XML PATH(”)),1,1,”)
FROM @TABLE T2
GROUP BY T2.ID
actually like your writing style, great details, thankyou for posting .
LikeLike
I actually wanted to write a small word so as to say thanks to you for all the nice concepts you are posting at this website. My considerable internet research has finally been paid with awesome information to go over with my friends and classmates. I ‘d state that that most of us site visitors actually are undeniably fortunate to be in a notable network with very many perfect professionals with helpful tactics. I feel very much fortunate to have come across your web pages and look forward to tons of more amazing times reading here. Thank you once more for a lot of things.
LikeLike
Say, you got a nice blog post.Much thanks again.
LikeLike
I have learn several good stuff here. Certainly value bookmarking for
revisiting. I surprise how a lot effort you put to make such a excellent informative site.
LikeLike
Outstanding post, I conceive weblog owners need to acquire a whole lot from this weblog its really user pleasant.
LikeLike
As soon as I located this internet web site I went on reddit to share some with the enjoy with them.
LikeLike
As I internet internet site possessor I believe the content material matter here is rattling amazing , appreciate it for your efforts. You must maintain it up forever! Very good Luck.
LikeLike
I undoubtedly did not realize that. Learnt something new nowadays! Thanks for that.
LikeLike
Wonderful web site. Lots of useful information here.
LikeLike
421814 84343I discovered your weblog internet site internet internet site on the internet and appearance some of your early posts. Continue to maintain inside the wonderful operate. I just now additional increase your Rss to my MSN News Reader. Seeking toward reading far far more from you obtaining out at a later date!… 285602
LikeLike
510625 510365Hey, you used to write fantastic, but the last few posts have been kinda boring¡K I miss your super writings. Past several posts are just just a little bit out of track! come on! 930274
LikeLike
828925 211049It’s hard to search out knowledgeable individuals on this subject, but you sound like you realize what you’re speaking about! Thanks 482382
LikeLike
whoah this blog is magnificent i adore reading your posts. Keep up the fantastic work! You know, lots of individuals are searching around for this info, you could assist them greatly.
LikeLike
Some genuinely rattling work on behalf of the owner of this website , utterly great content material .
LikeLike
An intriguing discussion is worth comment. I feel which you really should write far more on this subject, it may possibly not be a taboo topic but normally men and women are not enough to speak on such topics. Towards the next. Cheers
LikeLike
Outstanding post, I conceive individuals ought to larn a great deal from this web website its truly user genial .
LikeLike
122347 420709This is the sort of information I’ve long been in search of. Thanks for posting this information. 333176
LikeLike
A very good clear cut answer and a terrific concept. But how do I post any function on this internet site is one more question.
LikeLike
extremely nice put up, i really adore this web website, keep on it
LikeLike
231247 634596It’s truly a cool and helpful piece of info. I’m glad that you shared this helpful info with us. Please keep us informed like this. Thanks for sharing. 756796
LikeLike
I like this web site so significantly, saved to favorites .
LikeLike
Bookmarked your fantastic website. Fabulous work, unique way with words!
LikeLike