Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
hi i have a table like

degree_name - degree_id
AAA - 1
BBB - 2
CCC - 3

and i want fetch record like this
AAA,BBB,CCC

how to is possible

Thanks
Posted
Comments
[no name] 25-Jul-13 9:56am    
It is possible using a pivot, http://msdn.microsoft.com/en-us/library/ms177410(v=SQL.105).aspx
Joezer BH 25-Jul-13 10:09am    
Or
http://www.codeproject.com/Tips/500811/Simple-Way-To-Use-Pivot-In-SQL-Query
Maciej Los 25-Jul-13 10:52am    
Pivot? Not necessary...
Please, see my answer ;)
Maciej Los 25-Jul-13 10:46am    
:)laugh;)
Based on which criteria?
Please, be more specific and provide more details. Use "Improve question" widget.

Please, read my comment to the question.

You can use STUFF[^] or FOR XML PATH[^] statements ;)

Here is an example: Rolling up multiple rows into a single row and column for SQL Server data[^]
 
Share this answer
 
v2
Try this...
SQL
Select STUFF((Select Distinct ','+ DegreeName From TableName For XMl Path('')),1,1,'') as ColumnName

Check this link: http://www.sql-server-helper.com/tips/tip-of-the-day.aspx?tkey=3934817c-1a03-4ac9-a0ba-55b2bfbaea0f&tid=72&tkey=uses-of-the-stuff-string-function

If you want to Order the output u can do that by using this...
SQL
Select STUFF((Select Distinct ','+ DegreeName From TableName Order by ','+ DegreeName Desc 
		For XMl Path('')),1,1,'') [Comma Seperated List]
 
Share this answer
 
v3
Comments
[no name] 26-Jul-13 7:10am    
Thanks raja
Raja Sekhar S 26-Jul-13 7:11am    
You are Welcome....

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