--获得子节点,所有的子节点(不包括它自身). CREATE function f_GetChildId(@ID int) returns @tblReturn table(ParentDeptid int,Id int,name Nvarchar(50)) AS Begin insert into @tblReturn select ParentDeptid,Id,name from EPM_DepartmentList where ParentDeptid=@ID while @@rowcount>0 insert into @tblReturn select A.ParentDeptid,A.Id,A.name from EPM_DepartmentList A inner join @tblReturn B on A.ParentDeptid=B.Id where A.ID not in(select id from @tblReturn) return end
CREATE function f_GetChildId(@ID int)
returns @tblReturn table(ParentDeptid int,Id int,name Nvarchar(50))
AS
Begin
insert into @tblReturn select ParentDeptid,Id,name from EPM_DepartmentList where ParentDeptid=@ID
while @@rowcount>0
insert into @tblReturn select A.ParentDeptid,A.Id,A.name
from EPM_DepartmentList A inner join @tblReturn B on A.ParentDeptid=B.Id
where A.ID not in(select id from @tblReturn)
return
end