Jika Anda dapat memposting kueri yang menghasilkan tabel turunan, kami dapat membantu Anda menyelesaikannya , tetapi untuk saat ini coba ganti table1
dengan kueri turunan.
;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