Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
SELECT DISTINCT
a.ParentID,
STUFF( (SELECT ', ' + s.Children
FROM MyTable as s
WHERE s.ParentID = a.ParentID
FOR XML PATH(''), TYPE).value('.', 'varchar(max)')
,1, 2, '') as Children
FROM MyTable as a
WITH orderlyChildren AS (
SELECT ROW_NUMBER() OVER (PARTITION BY ParentId ORDER BY ChildName) ChildNumber, *
FROM yourTable
)
SELECT ParentId,
MAX(CASE ChildNumber WHEN 1 THEN ChildName END) Child1,
MAX(CASE ChildNumber WHEN 2 THEN ChildName END) Child2
FROM orderlyChildren
GROUP BY ParentId