Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
vision.v1
Yak Posting Veteran
72 Posts |
Posted - 2013-04-25 : 11:17:02
|
Hi,I have below table in which i have countryCodes but i want the result to return in comma-seperated instead of rowsCREATE 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 #tempCountryCodes------------1234Expected Output---------------1,2,3,4Please advise.Thanks |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-25 : 11:43:49
|
[code]SELECT STUFF((SELECT ',' + CAST(countrycodes AS varchar(5)) FROM #temp ORDER BY countrycodes FOR XML PATH('')),1,1,'')[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|