sqlserver 合并列数据的实现
sql server 递归查询树型结构某节点的所有上级节点,并且把这些所有上级节点多行拼接为一行,即合并列数据
with eps_root(pk_eps, pk_parent, ephpps_code, eps_name) as ( SELECT pk编程_eps, pk_parent, eps_code, eps_name FROM pm_eps http://www.devze.com where ena开发者_Hiveblestate = 2 and pk_eps = '1001A11000000003P62E' union all SELECT e.pk_eps, e.pk_parent, e.epsjs_code, e.eps_name FROM pm_eps e inner join eps_root r on e.pk_eps = r.pk_parent where e.enablestate = 2 ) select distinct eps_code = stuff((select '/' + convert(nvarchar(500), eps_code) from (pythonselect distinct eps_code from eps_root) r1 for XML path('')), 1, 1, ''), --此次需要使用eps_code排序,不然中文的会错乱顺序 eps_name = stuff((select '/' + eps_name from (select top 99.99 PERCENT eps_name from eps_root order by eps_code) r2 for xml path('')), 1, 1, '') from eps_root
执行sql,如下图效果:
到此这篇关于sqlserver 合并列数据的实现的文章就介绍到这了,更多相关sqlserver 合并列数据内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!
精彩评论