zhouer 发表于 2018-10-20 10:41:38

SQL字符串合并

---去重  
select id, = stuff((select distinct ',' + from #tb t where id = #tb.id for xml path('')) , 1 , 1 , ''),max(isnull(cname,''))
  
from #tb
  
group by id
  
---不去重
  
select id, = stuff((select ',' + from #tb t where id = #tb.id for xml path('')) , 1 , 1 , ''),max(isnull(cname,''))
  
from #tb
  
group by id


页: [1]
查看完整版本: SQL字符串合并