I want to concatenate values from 1 column and group by another. I've seen many solutions to this (using FOR XML PATH('')
for example) but I've not come across one that uses more than 1 table. I need the second table to filter out some entries and I can't figure out how to do it.
My data looks like this:
SONo PartNo
1 A04000.1 M41000M
2 A04000.1 M52000M
3 A04001.1 V31255
4 A04001.1 V32895
I want it to look like this:
SONo PartNo
1 A04000.1 M41000M, M52000M
2 A04001.1 V31255, V32895
My query looks like this:
SELECT SUBSTRING(Table1.ID, 5, 10) AS SONo, Table1.PartNo
FROM Table1 INNER JOIN
Table2 ON Table1.PartNo = Table2.PartNo
WHERE (Table2.StoreNo = '13')
ORDER BY SONo
Any help would be much appreciated.
Thanks.