链接地址:http://www.cnblogs.com/aolin/archive/2011/04/12/2014122.html
http://blog.163.com/zhi_qingfang@126/blog/static/11747756320132693434495/
http://blog.csdn.net/rolamao/article/details/7745972
示例表 tb 数据如下
id value
—————
1 aa
1 bb
2 aaa
2 bbb
2 ccc
第一种
SELECT id, [ val ] = ( SELECT value ] + ' ,0); line-height:1.5!important">' FROM tb AS b WHERE b.id = a.id FOR XML PATH( '' ) ) AS a
1 aa,bb,
2 aaa,bbb,ccc,
第二种
AS a GROUP BY id
第三种 (用STUFF函数替换掉首端的逗号)