SajjadZare
SajjadZare

Reputation: 2378

Concatenate multiple rows into one field

I have a table with three column like image (Source) and want to write a query that give a table like image (Result)

enter image description here

Upvotes: 0

Views: 1870

Answers (1)

KumarHarsh
KumarHarsh

Reputation: 5094

SELECT DISTINCT customer,
    stuff((
            SELECT ',' + cast(policy as varchar(10))
            FROM table1 b
            WHERE a.customerid = b.customerid
            FOR XML path('')
            ), 1, 1, '') [policies]
FROM table1 a

Upvotes: 6

Related Questions