Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
sir, i have a table in which one column that name StudentID. the result of this table is look like:-

StudentID

101
102
103

but i need a query that show result in a single row. and look like :-

StudentID
101,102,103


How can i do it?
Posted
Comments
Thanks7872 17-Sep-14 7:31am    
Why?

1 solution

Use Stuff

SQL
SELECT STUFF((SELECT ', ' + [StudentID] FROM YOURTABLE FOR XML PATH('')),1,1,'') as [StudentID]
GO


If your column is not a string then you need to cast

SQL
SELECT STUFF((SELECT ', ' + CONVERT(varchar(10), StudentID) FROM Emp2 FOR XML PATH('')),1,1,'') as id
GO
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900