一個用於樹的存儲過程
create proc TS_P008
@in_deptid varchar(23),
@in_len int
AS
-- 查詢部門
-- jzl
-- 2006-12-15
-- @in_deptid 當前節點的編號 第一次調用時爲空
-- @in_len 當前節點的編號的長度加2
if len(@in_deptid) =0
begin
select b.deptName,b.DeptID,
'child'=case(select count(*) from US_DeptStation a where a.deptid like b.deptid+'__' )
when 0 then 0 else 1 end
from US_DeptStation b where deptflag=0 and len(DeptID)=2
end
else
begin
select b.deptName,b.DeptID,
'child'=case(select count(*) from US_DeptStation a where a.deptid like b.deptid+'__')
when 0 then 0 else 1 end
from US_DeptStation b
where deptflag=0
and len(DeptID)=@in_len
and deptid like @in_deptid+'%'
end