SELECT B.id ,
LEFT(tempname, LEN(tempname) - 1) AS name
FROM ( SELECT id ,
( SELECT name + ','
FROM tablename
WHERE id = A.id
FOR
XML PATH('')
) AS tempname
FROM tablename A
GROUP BY id
) B

posted on 2015-05-08 14:29  hegang  阅读(470)  评论(0编辑  收藏  举报