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)
 Concatenate Rows to a singel row

Author  Topic 

callawayx14
Yak Posting Veteran

73 Posts

Posted - 2009-01-15 : 11:01:11
Hello,

I'm trying to concatenate multiple rows into a songle row. The data loks like this

Request | User
1234 | Bob
1234 | Jim
1234 | Bill

I would like to see 1234 | Bob, Jim, Bill

I appreciate any help. Thank you!!

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-01-15 : 11:12:30
Try this:


SELECT DISTINCT m.Request,STUFF((SELECT ','+ [User] FROM @Table WHERE Request = m.Request FOR XML PATH('')),1,1,'')as [User]
FROM @Table m
Go to Top of Page

callawayx14
Yak Posting Veteran

73 Posts

Posted - 2009-01-15 : 11:36:57
This doesn't seem to work for me. I appreiate the helo though
Go to Top of Page

PingTheServer
Starting Member

28 Posts

Posted - 2009-01-15 : 12:21:06
quote:
Originally posted by callawayx14

This doesn't seem to work for me. I appreiate the helo though



You might need to convert them to Strings first, STR(Request)
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-01-15 : 12:24:03
quote:
Originally posted by PingTheServer

quote:
Originally posted by callawayx14

This doesn't seem to work for me. I appreiate the helo though



You might need to convert them to Strings first, STR(Request)



Why?
Go to Top of Page

PingTheServer
Starting Member

28 Posts

Posted - 2009-01-15 : 12:27:28
I remember banging my head concatenating columns once and converting them solved my problem.

IDK its just a guess.
Go to Top of Page
   

- Advertisement -