select PR.Id, PR.Name as RoleName, Left(Final.UserList, LEN(Final.UserList) - 1) as Members
from ProjectRoles PR
left join (select ProjectRoleId,(
select Name + ','
from (select M.ProjectRoleId, U.Name
from ProjectMembers M
join Users U on M.UserId = U.Id) SourceTB
where SourceTB.ProjectRoleId = PM.ProjectRoleId
order by ProjectRoleId for xml path('')) as UserList
from (select M.ProjectRoleId, U.Name
from ProjectMembers M
join Users U on M.UserId = U.Id) PM
group by ProjectRoleId) Final on PR.Id = Final.ProjectRoleId
有点乱 !!