用於處理樹的一個存儲過程

一個用於樹的存儲過程
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
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章