代码如下:

View Code
 1 with temp(nodeid,nodename,parentid) as
2 (
3 select ou.nodeid,ou.nodename,ou.parentid from OU ou where ou.parentid=(select parentid from OU where nodeid ='010201')and ou.nodeid='010201'
4 union all
5 select ou.nodeid,ou.nodename,ou.parentid from OU ou,temp tm where ou.nodeid=tm.parentid
6
7 )
8 select * from temp
9 go
10 注:ou.nodeid=tm.parentid是从本部门向上递归(即查出本部门以上的部门包括本部门)
11 ou.parentid=tm.nodeid是从本部门向上递归(即查出本部门以下的部门包括本部门)

 

相关文章:

  • 2021-12-19
  • 2021-06-12
  • 2021-08-29
  • 2021-09-23
  • 2022-12-23
  • 2021-12-26
  • 2021-11-13
  • 2021-12-09
猜你喜欢
  • 2021-11-04
  • 2021-05-31
  • 2021-10-07
  • 2021-12-12
  • 2022-12-23
  • 2021-09-08
  • 2021-07-24
相关资源
相似解决方案