Possible Duplicates:
Simulating group_concat MySQL function in MS SQL Server 2005?
Concatenate values based on ID
I am trying to write a SQL query in SSMS 2008 to group by a single column. I have a table with just two columns: Part Number and Product Code. Both of these columns are VARCHAR data types.
Right now my table looks something like:
Part Number Product Code
111222 AAAAA
111222 BBBBB
111222 CCCCC
111223 AAAAA
111224 AAAAA
111225 AAAAA
111226 DDDDD
111226 EEEEE
But I want this table to instead look like:
111222 AAAAA, BBBBB, CCCCC
111223 AAAAA
111224 AAAAA
111225 AAAAA
111226 DDDDD, EEEEE
How do I do this? I have read some websites recommending coalesce function, but I can't seem to figure out a way to get this to work correctly.