Fork me on GitHub
.net求学者

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

 

posted @ 2014-01-16 11:04  hy31337  阅读(145)  评论(0编辑  收藏  举报
.net求学者