1. 程式人生 > >sqlserver 根據子節點查詢所有父節點

sqlserver 根據子節點查詢所有父節點

with partents as
(
select * from b_sys_org_adm where ORG_CODE ='ADM_100010301013'
UNION ALL
 (SELECT a.* from b_sys_org_adm as a inner join
  partents as b on a.ORG_CODE=b.ORG_PCODE
 )
)
SELECT ORG_CODE,ORG_NAME FROM partents ;