SELECT 字段=(SELECT b.合并字段+',' FROM 表一 AS b WHERE b.相同条件=a.相同条件 FOR XML PATH('')) FROM 表一 AS a
DECLARE @temp TABLE (caccount VARCHAR(50), icaccount VARCHAR(50))
INSERT INTO @temp
SELECT a.caccount,b.caccount AS icaccount
FROM op_client_main_caccount a
LEFT JOIN op_client_correlate_caccount b ON a.id=b.id
WHERE b.caccount IN ('AT2478','2V5588','E8840R','ST014','ST017')
-- SELECT * FROM @temp
SELECT caccount,cemos=(SELECT icaccount+',' FROM @temp b WHERE b.caccount=a.caccount FOR XML PATH(''))
FROM @temp a
GROUP BY a.caccount