The following will concatenate all children names belonging to the parent with a ',' delimiter.
SELECT DISTINCT parent.id, parent.name, CA, CB
FROM ParentTable parent
CROSS APPLY
(
SELECT child.name + ','
FROM ChildA child
WHERE child.parentId = parent.id
ORDER BY child.name
FOR XML PATH('')
) childA(CA)
CROSS APPLY
(
SELECT child2.name + ','
FROM ChildB child2
WHERE child2.parentId = parent.id
ORDER BY child2.name
FOR XML PATH('')
) childB(CB)
No comments:
Post a Comment