sql把表格拼成字符串,多半使用于GROUP BY
--假定要聚合的字段是id ,要统计的字段是tname --select a.tname from @T1 a for xml path('row') select id,REPLACE(replace((select a.tname from @T1 a where a.id=t.id for xml path('row')),'<row><tname>',''),'</tname></row>',',') from @T1 t group by id