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
 Transact-SQL (2008)
 question concatanating

Author  Topic 

joe8079
Posting Yak Master

127 Posts

Posted - 2012-05-15 : 11:08:08
Hi, I have a very complicated issue and I don't know where to go.
Basically, I need a way to concatanate lines 1-3 into one string and keep all the commas. The desired output is below. In my database, I have over 3.5 million records that look like this and some have ten of the same box with a different for each box. It would need to show one unique box by somehow concatanting all the columns below it. My co worker suggested some kind of loop, but I have no idea where to even begin. Also, the loop would have to run like 3.5 million times so I'm not sure how this would affect performance. Any help would be greatly appreciated.



Box String:
B3399 ,123, , ,
B3399 ,345 , ,
B3399 ,123, 41, ,
Desired output:

Box String
B3399 ,123, , , ,345 , , ,123, 41, ,

joe8079
Posting Yak Master

127 Posts

Posted - 2012-05-15 : 11:12:23
just so its clear, the Box is B3399 and the column for String starts with a ,
Its two separate columns and the formatting got messed up when I posted it.
Go to Top of Page

joe8079
Posting Yak Master

127 Posts

Posted - 2012-05-15 : 19:29:24
I actually just figured this one out. I had to use the For XML() function to concatanante the rows together.
Go to Top of Page
   

- Advertisement -