Need help creating a request

I get the following result after joining three tables:

col1 col2 col3
 1    2    Pr1
 1    2    Pr2
 1    2    Pr3

But I need the result to be like this:

col1 col2 col3
 1    2    Pr1,Pr2,Pr3
+3
source share
1 answer

In MS SQL 2005/2008:

select
    col1,
    col2,
    col3 = (
        select col3 + ','
        from TestTable
        for xml path('')
    )
from TestTable
group by col1, col2

Here you can find how to do the same in 2000, as well as how to get rid of the final comma: Create a comma-delimited list from a column

+1
source

All Articles