Convert all rows into a single column output | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Convert all rows into a single column output

I have a table Numbers:
Nos
123
456
789
I need a query to display the output as : 123,456,789 How can this be done?
declare @str as varchar(4000) Set @str =”
Select @str = cast(nos as varcahr(10)) + ‘,’ from TableName
Print @str —————————————-
Contributing Editor, Writer & Forums Moderator
http://www.SQL-Server-Performance.Com Visit my Blog at
http://dineshasanka.spaces.live.com/

This doesnt work : This just displays the last row with a comma
789, what i need is all the rows : 123,456,789
small change need declare @str as varchar(4000) Set @str =”
Select @str = @str + cast(nos as varcahr(10)) + ‘,’ from TableName
Print @str Sorry about it —————————————-
Contributing Editor, Writer & Forums Moderator
http://www.SQL-Server-Performance.Com Visit my Blog at
http://dineshasanka.spaces.live.com/

Note that if the concatenated strings exceed more than 8000 characters, you need to use more than one variable Madhivanan Failing to plan is Planning to fail
Yup. Thanks a lot for your help.
]]>