如何获取树结构中多个节点的所有子节点?

How to get all children of several nodes in tree structure?

我有一个 table 层次结构如下:

 Create Table tbl1 
 (
     AccountID  NVARCHAR(100), 
     ID int, 
     ParentID int
 );

 INSERT INTO tbl1 
 VALUES ('11', 1, Null), ('12', 2, Null), ('13', 3, Null),
        ('11/11', 4, 1), ('11/12', 5, 1), ('11/111', 6, 1),
        ('11/11/001', 7, 4), ('11/11/002', 8, 4), ('12/111', 9, 2),
        ('12/112', 10, 2);

如何从树结构中的 tbl1 中获取某些节点的所有子节点,根据另一个 table (FilteringTbl) 像这样:

 AccountID  
 ---------
 11/11
 12
 13

换句话说,我想创建一个 SQL 查询,以从 SQL 服务器中的第一个 table (tbl1) 获取节点 11/11、12 和 13 的所有子节点2008. 主要 tables 有超过 5000 条记录。 (tbl1 5400 条记录和过滤 tbl 1500 条记录)

请帮助我。谢谢

;with C
as (
    select  AccountID,
            ID,
            ParentID,
            0 as [level]
    from    tbl1
    where   ID IN (SELECT ID FROM Filteringtbl)
    union all
    select  I.AccountID,
            I.ID,
            I.ParentID,
            C.[level] + 1 as [level]
    from    tbl1 as I
            inner join C on
                C.ID = I.ParentID
)
select  *
from    C