Please consider the following sample data:
Part Loc Qty
A A-1 10
A A-5 15
A B-4 7
B B-5 10
B B-6 15
I can query easily enough to get the location qty for each part:
select
pt.Part
,lc.Loc
,lc.LocQty Qty
from
Part pt
left join
Loc lc
on
pt.Part = lc.Part
I can also sum the locations like so:
select
pt.Part
,sum(lc.LocQty) TotalQty
from
Part pt
left join
Loc lc
on
pt.Part = lc.Part
group by
pt.Part
What I want to do now is instead concatenate into a new column, each location that the part appears, like so:
Part TotalQty InLocations
A 32 A-1, A-5, B-4
B 25 B-5, B-6
What would be the best approach to this?
Many thanks