--查找某节点的所有子节点(包含自己)
alter function rerr(@dep int)
returns @table table (TDtID int )
as
begin
insert into @table
select tdtid from TDept where tdtpid=@dep;
begin
while @@rowcount >0
insert @table
select a.tdtid from TDept a inner join @table b on a.tdtpid=b.tdtid and a.tdtid not in (select * from @table)
--子级的父级部门ID=父级的部门ID
end
insert @table
select tdtid from TDept where tdtid =7; --包含自己就加上这一句话
return
end