select distinct UserId,STUFF((SELECT ',' + CONVERT(VARCHAR, RoleId)
FROM UserRole WHERE UserId=D.UserId
FOR XML PATH('')), 1, 1, '')AS BackRoleName
FROM UserRole D GROUP BY UserId,RoleId
转载于:https://www.cnblogs.com/zhouzhe/p/5681889.html
select distinct UserId,STUFF((SELECT ',' + CONVERT(VARCHAR, RoleId)
FROM UserRole WHERE UserId=D.UserId
FOR XML PATH('')), 1, 1, '')AS BackRoleName
FROM UserRole D GROUP BY UserId,RoleId
转载于:https://www.cnblogs.com/zhouzhe/p/5681889.html