sql server 多行合并

     不说废话了,看语句: 

select name from sysuser for xml path('person')

 

结果:

<person><name>aa</name></person><person><name>bb</name></person><person><name>cc</name></person>

  

2.

 select ','+name from sysuser for xml path('')

 结果:

,aa,bb,cc

 3.

select d.shortname, stuff( (select ',' + u.name from sysuser as u  where u.deptid=d.id for xml path('')),1,1,'') 
 from systemdept as d 


                            

你可能感兴趣的:(SQL Server)