sql 递归调用
来源:互联网 发布:虚拟机访问windows盘 编辑:程序博客网 时间:2024/06/05 14:53
Id
Name
Parent_id
Audit_start
Audit_end
1
Client1
<null>
2008.08.02
<null>
2
Division1
1
2008.08.02
<null>
3
Division2
2
2008.08.02
<null>
----------------------------------------------------------------------
declare @clientId int
set @clientId = 1
-----------------------------------------------------------------
--get all subclients belong to this client including itself.
declare @tbl_clients table
(
client_id int,
client_name varchar(100),
level int
)
----------------------------------------------------------
--insert itself
insert into @tbl_clients (client_id,client_name,level)
select @clientId,name,0
from clients
where id= @clientId and audit_end is null
--insert its children
declare @level int
set @level=1
insert into @tbl_clients
select id,name,@level from clients where parent_id=@clientId and audit_end is null
while @@rowcount>0
begin
set @level=@level+1
insert into @tbl_clients
select clients.id, clients.name,@level
from clients,@tbl_clients tmp
where clients.parent_id=tmp.client_id
and tmp.level=@level-1
and clients.audit_end is null
end
select * from @tbl_clients
select * from clients where audit_end is null
- sql 递归调用
- SQL Server:触发器调用 - 存储过程递归删除父子类
- 简单几招捕获Oracle递归SQL调用源头
- 递归调用
- 递归调用
- 递归调用
- 递归调用
- 递归调用
- 递归调用
- 递归调用
- 递归调用
- 递归调用
- 递归调用
- 递归调用
- 递归调用
- 递归调用
- 递归调用
- 递归调用
- 需求导向的软件构件技术
- 正则表达式工具
- ▆▆◣淘宝信用炒作全攻略(教你识别初级到终极炒作的手法)(转载)
- 百度封你网站的几个可能因素
- js获取鼠标点击位置(很旧很旧。。。)
- sql 递归调用
- linux系统locale的设定
- "信托"专替卖家刷淘宝信用 制造虚假交易赚人气
- Asp木马技术分析
- 用eclipse调试struts时报错org.apache.struts.config.FormBeanConfig.createActionForm(FormBeanConfig.java:289)
- Asterisk学习资料
- 淘宝卖家信用升级方案
- 对list的中的bean的某属性排序的方法
- 如何实现C51和汇编的混合编程