SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to convert rows to comma seperated row
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vision.v1
Yak Posting Veteran

71 Posts

Posted - 04/25/2013 :  11:17:02  Show Profile  Reply with Quote
Hi,

I have below table in which i have countryCodes but i want the result to return in comma-seperated instead of rows

CREATE TABLE #temp
(
countrycodes INT
)

INSERT #temp SELECT '01'
INSERT #temp SELECT '02'
INSERT #temp SELECT '03'
INSERT #temp SELECT '04'

Current Output
---------------

SELECT countrycodes from #temp

CountryCodes
------------
1
2
3
4

Expected Output
---------------

1,2,3,4

Please advise.

Thanks

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 04/25/2013 :  11:43:49  Show Profile  Reply with Quote

SELECT STUFF((SELECT ',' + CAST(countrycodes AS varchar(5)) FROM #temp ORDER BY countrycodes FOR XML PATH('')),1,1,'')


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000