使用with进行回溯

来源:互联网 发布:canon mp280清零软件 编辑:程序博客网 时间:2024/06/11 11:07

 with dept(deptID,pDeptID)
 as
 (select uDepID,uParentID from OA.dbo.DepInfo where uDepID in(
  select p.uDepID from OA.dbo.PostInfo as p
  inner join OA.dbo.UserInPost as up on p.uPostID=up.uPostID
  where up.uUserID=@UserID)
  union all
 select uDepID,uParentID from OA.dbo.DepInfo as di
  inner join dept as d on di.uDepID=d.pDeptID
  where di.uParentID is not null
 )

原创粉丝点击