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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 concatenating all the rows of a column

Author  Topic 

akash-alo
Starting Member

1 Post

Posted - 2009-08-19 : 06:01:47
Can anyone show me a way of getting concatenated string all the rows of a table?

maeenul
Starting Member

20 Posts

Posted - 2009-08-19 : 06:06:46
Hello,

Its very easy to do that. There is a nice given in the following link.

http://www.programmingsolution.net/sqlserver2005/sqlserver-solutions/display-article.php?article-id=20

This is a common scenario. If anyone else have any other better way of doing it, Please let us know.



-----------------------
maeenul
http://www.programmingsolution.net/sqlserver2005/sqlserver-solutions/
http://sqlservertipsntricks.blogspot.com
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-08-19 : 06:46:18
quote:
Originally posted by akash-alo

Can anyone show me a way of getting concatenated string all the rows of a table?


Why do you want to do this?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-08-19 : 08:06:00
Hi , u want this


declare @temp table (id int)
insert into @temp select 1
insert into @temp select 2
insert into @temp select 3
insert into @temp select 4
insert into @temp select 5
insert into @temp select 6

select distinct stuff((select distinct ','+cast(id as varchar(32))
from @temp for xml path('')),1,1,'') as val from @temp

Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-08-19 : 08:39:10
Try this too

select (SELECT column_name+ ',' as [text()] FROM table_name
FOR XML PATH('')) as alias_name

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page
   

- Advertisement -