Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grouping a column with comma-separated elements.

Status
Not open for further replies.

mabho

Programmer
Aug 28, 2006
11
BR
Hi,

People, I need to write a query in SQL Server that groups together different elements from a column using some separator like a comma.

I have a table that is more or less like this:
[tt]
++++++++++++++++++++++++++++++++++++++++++
+ department1 + John +
+ department1 + Lara +
+ department1 + Jim +
+ department2 + Cynthia +
+ department2 + Charles +
++++++++++++++++++++++++++++++++++++++++++
[/tt]

I want to write a query to get the following result:
[tt]
++++++++++++++++++++++++++++++++++++++++++
+ department1 + John, Lara, Jim +
+ department2 + Cynthia, Charles +
++++++++++++++++++++++++++++++++++++++++++
[/tt]
How can I achieve that? Thanks in advance!
 
Please, have a look at this FAQ.

faq183-2146



Sunil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top