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