0

Possible Duplicate:
Concatenate a selected column in a single query?

I know this is fairly simple in MySQL, but i don't know how to do it in SQLServer. I have a table containing two columns. UserID & TagID. I'd like to concatenate TagID into a comma separated string, where the result is grouped by UserID. How can i do that?

Community
  • 1
  • 1
Anton Gildebrand
  • 3,641
  • 12
  • 50
  • 86

1 Answers1

0

I would ythink something lik ethis might be what you are looking for :

SELECT ''+Table1.UserID+','+Table2.TagID+'' AS CombinedCSVColumn
      , SUM(Table1.Value) AS Value
From dbo.Table1 as Table1
INNER JOIN db.Table2 as Table2
ON Table1.EmployeeID = Table2.EmployeeID
GROUP BY ''+Table1.UserID+','+Table2.TagID+'' 

That is if they come from two Tables. For one table is similar.

Regards

Mac

Andrew McLintock
  • 142
  • 1
  • 5
  • 14
  • This is only possible when i know exactly how many items to concatinate, but it's dynamic and per User how many they are. – Anton Gildebrand Apr 24 '12 at 12:14
  • Did my code help you? If not - let me have more info and I will see what I can do for you, otherwise, award it as having answered the question you first asked. Cheers, Mac – Andrew McLintock Apr 24 '12 at 12:17