SQL SERVER 同一字段,整合同类项

select * from dbo.test with(nolock)
select
name,
stuff((select distinct ','+cast(code as varchar(30)) from dbo.test where name=t.name for xml path('')),1,1,'') as code
from dbo.test t
group by name

select * from dbo.test with(nolock)
select
name,
stuff((select distinct ','+cast(code as varchar(30)) from dbo.test where name=t.name for xml path('')),1,1,'') as code
from dbo.test t
group by name