sql通过一个节点ID得到所有子节点

来源:互联网 发布:海尔智能家居网络设置 编辑:程序博客网 时间:2024/05/15 18:42

declare @Bddr table
(
AddrId varchar(100)
);
With RootNodeCTE(Id,ParentId)
As
(
Select AddrId,AddrParent From gs_AddressInfo Where AddrParent In (@AddrID)
Union All
Select gs_AddressInfo.AddrId,gs_AddressInfo.AddrParent From RootNodeCTE
Inner Join gs_AddressInfo
On RootNodeCTE.Id = gs_AddressInfo.AddrParent
)insert into #Bddr (AddrId)  select Id from  RootNodeCTE where Id not in(select ParentId from RootNodeCTE)

;

原创粉丝点击