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.
Author |
Topic |
12many
Starting Member
9 Posts |
Posted - 2013-03-14 : 06:53:32
|
Hi ThereI have a Table GroupmembersGroupId | Member1 51 61 72 82 92 10I would like a result Like Group | GroupMembers 1 5,6,7 2 8,9,10 I found this query on line and it does return the delimited membersDECLARE @list VARCHAR(MAX)SELECT @list = COALESCE(@listStr+',' ,'') + CONVERT(VARCHAR(4),member)FROM groupmembers WHERE group = 1SELECT @listThe problem here is that i can't then use this as a sub query.Can any one Help Many thanks Ian |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-03-14 : 07:31:20
|
SELECT t1.GroupId, STUFF((SELECT ',' + CAST(s.Member AS VARCHAR) FROM @t s WHERE s.GroupId = t1.GroupId FOR XML PATH('')),1,1,'') AS CSVFROM @t t1GROUP BY t1.GroupId--Chandu |
|
|
|
|
|