Introduction
Suppose I have a table as in the following.

And you need to return all the names as a comma-separated string, as in the following.
Rahul Saxena, Sara Sinha, Priyanka Mathur, Shambhu Sharma, Manu Khanna, Ganga, Shweta, Shraddha, Akhilesh, Mayank, Rakesh, Abhishek, Saurabh
Use the following command.
SELECT SUBSTRING((
SELECT ',' + CAST(Name AS VARCHAR) FROM Employee
FOR XML PATH('')), 2,10000) AS NAME
If you want to provide a condition then.
SELECT SUBSTRING((
SELECT ',' + CAST(Name AS VARCHAR) FROM Employee WHERE Country='India'
FOR XML PATH('')), 2,10000) AS NAME
If you want to show your result group by a column, then use the following query.
SELECT DISTINCT Country,
STUFF(
(
SELECT ',' + CAST(Name AS VARCHAR)
FROM Employee AS t2
WHERE t2.Country = t.Country
FOR XML PATH('')
), 1, 1, '') AS id_list
FROM Employee AS t


Rahul Kumar SaxenaTOP 100Posted Mar 31, 2015, 9:02 AM EDT
Thanks Tom Mohan...
Rahul Kumar SaxenaTOP 100Posted Mar 31, 2015, 9:02 AM EDT
Thanks Karthik Muthu Karuppan..
Rahul Kumar SaxenaTOP 100Posted Mar 31, 2015, 9:02 AM EDT
Thanks Santhakumar Munuswamy...
Rahul Kumar SaxenaTOP 100Posted Mar 31, 2015, 9:02 AM EDT
Thanks Gowtham Rajamanickam..
Rahul Kumar SaxenaTOP 100Posted Mar 31, 2015, 9:02 AM EDT
Thanks Khargesh Rajput..
Rahul Kumar SaxenaTOP 100Posted Mar 31, 2015, 9:01 AM EDT
Thanks Nitin Tyagi...
Tom MohanPosted Mar 31, 2015, 8:31 AM EDT
good show
Karthik Muthu KaruppanPosted Mar 31, 2015, 6:58 AM EDT
nice
Santhakumar MunuswamyPosted Mar 31, 2015, 2:37 AM EDT
Thanks for nice one
Gowtham RajamanickamTOP 100Posted Mar 31, 2015, 2:02 AM EDT
good one..
Khargesh RajputPosted Mar 31, 2015, 1:57 AM EDT
nice
NitinPosted Mar 30, 2015, 11:32 PM EDT
Good one