with eps_root(pk_eps, pk_parent, eps_code, eps_name) as
(
SELECT
pk_eps, pk_parent, eps_code, eps_name
FROM pm_eps
where enablestate=2
and pk_eps=’1001A11000000003P62E’
union all
SELECT
e.pk_eps, e.pk_parent, e.eps_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
pk_eps, pk_parent, eps_code, eps_name
FROM pm_eps
where enablestate=2
and pk_eps=’1001A11000000003P62E’
union all
SELECT
e.pk_eps, e.pk_parent, e.eps_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 (select 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
© 版权声明
文章版权归作者所有,未经允许请勿转载。