Is it possible to "merge" the values of multiple records into a single field without using a stored

Posted by j0rd4n on Stack Overflow See other posts from Stack Overflow or by j0rd4n
Published on 2010-03-25T22:35:49Z Indexed on 2010/03/25 22:43 UTC
Read the original article Hit count: 371

Filed under:
|

A co-worker posed this question to me, and I told them, "No, you'll need to write a sproc for that". But I thought I'd give them a chance and put this out to the community.

Essentially, they have a table with keys mapping to multiple values. For a report, they want to aggregate on the key and "mash" all of the values into a single field. Here's a visual:

---  -------
Key  Value
---  -------
1    A
1    B
1    C
2    X
2    Y

The result would be as follows:

---  -------
Key  Value
---  -------
1    A,B,C
2    X,Y

They need this in SQLServer 2005. Again, I think they need to write a stored procedure, but if anyone knows a magic out-of-the-box function that does this, I'd be impressed.

© Stack Overflow or respective owner

Related posts about sql-server-2005

Related posts about query