Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hello, I'm trying to concatenate multiple rows into a songle row. The data loks like thisRequest | User1234 | Bob1234 | Jim1234 | BillI would like to see 1234 | Bob, Jim, BillI 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
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
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)
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?
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.