Hvis du kan sende forespørgslen, den producerer afledte tabel, kan vi hjælpe dig med at finde ud af det , men prøv i øjeblikket at erstatte table1
med den afledte forespørgsel.
;WITH Table1
AS
(
SELECT C1, C2, C3 FROM T1 WHERE C1 IS NOT NULL--and a lot of calculation also
)
SELECT
C1,C2,
STUFF(
(SELECT ',' + C3
FROM Table1
WHERE C1 = a.C1 AND C2 = a.C2
FOR XML PATH (''))
, 1, 1, '') AS NamesList
FROM Table1 AS a
GROUP BY C1,C2