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 2008 Forums
 Other SQL Server 2008 Topics
 Concatenate rows

Author  Topic 

A-Man
Starting Member

1 Post

Posted - 2011-07-26 : 00:37:45
Hi,
I am using SQL Server 2005. I have a table with three columns like this
a --- 1 --- A
a --- 2 --- A
b --- 1 --- B
b --- 2 --- B
b --- 3 --- B

I would like to insert it into another table as

a --- 1,2 --- A
b --- 1,2,3 --- B

Any suggestions please.

sayan751
Starting Member

4 Posts

Posted - 2011-07-26 : 01:02:02
You can make use of a cursor, that will concat the value of second col provided the first and third col value is same in consecutive row and insert the newly constructed row in a table, if the value is not same then break the loop and start constructing a new row.

Hope that will help!
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2011-07-26 : 09:20:15
search the forum for "FOR XML". There are some examples to do the rows to columns and from there you should be able to work out the insert
Go to Top of Page
   

- Advertisement -