05 版本以上可以用 XML select Table1.*
,stuff((select ','+RoleId from Table2 where Table2.UserId=Table1.UserId for xml path('')),1,1,'') RoleIds 
from Table1