For hvert par EntityID, AttributeID
brug XML-sti-tricket til at generere CSV'en
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)