Может быть, что-то вроде этого:
Данные испытаний
DECLARE @tbl TABLE(ID INT,Category VARCHAR(100))
INSERT INTO @tbl
VALUES
(1,'a'),
(1,'b'),
(2,'a'),
(2,'b'),
(2,'c')
Запрос
;WITH CTE ----CTE Name
AS
(
SELECT
ROW_NUMBER() OVER(PARTITION BY ID ORDER BY ID) AS RowNbr,
ID,
Category
FROM
@tbl AS tbl
)
SELECT
CTE.ID,
(
STUFF
((
SELECT
','+Category
FROM @tbl AS tbl
WHERE tbl.ID=CTE.ID
FOR XML PATH('')
)
,1,1,'')
) AS Category
FROM
CTE
WHERE
CTE.RowNbr=1