Voor elk paar EntityID, AttributeID
gebruik de XML-padtruc om de CSV te genereren
SELECT
M.EntityID, M.AttributeID,
SUBSTRING(CAST(foo.bar AS varchar(8000)), 2, 7999) AS Options
FROM
(
SELECT DISTINCT EntityID, AttributeID
FROM MyTable
) M
CROSS APPLY
(
SELECT
',' + OptionText
FROM
MyTable M2
WHERE
M.EntityID = M2.EntityID AND M.AttributeID= M2.AttributeID
FOR XML PATH ('')
) foo(bar)