I'm having a bit of trouble implementing the XML PATH method of concatenating multiple rows. So, given the following table, Test.
ID Type
1 boy
2 boy
3 boy
1 girl
2 girl
3 man
3 woman
The query is:
SELECT DISTINCT a.ID,
(
SELECT b.Type + ','
FROM Test as b
WHERE a.Type = b.Type
for XML PATH ('')
)
FROM Test as a
but instead of returning:
ID Type
1 boy,girl,man,
2 boy,girl,
3 boy,girl,woman
it instead returns this:
ID Type
1 boy,boy,boy,
1 girl,girl,
2 boy,boy,boy,
2 girl,girl,
3 boy,boy,boy,
3 man,
3 woman,
What's going on?