存储过程递归
来源:互联网 发布:后会无期 知乎 编辑:程序博客网 时间:2024/05/18 22:55
表
create table #t(dept varchar(5),parentdept varchar(5))
insert into #t
select 'A0401','A0400' union
select 'A0400','C0300' union
select 'C0300','B0200' union
select 'B0200','0' union
select 'E0501','E0500' union
select 'E0500','E0101'
存储过程
CREATE proc dt_path(@dept varchar(5),@flag int=0) --@flag 默认值为0
as
declare @parentdept varchar(5)
if @flag=0
create table #qq(dept varchar(5))
select @parentdept=parentdept from #t where dept=@dept
if @parentdept<>'0'
begin
insert into #qq select @dept
exec dt_path @parentdept,1
end
else
begin
insert into #qq select @dept
select * from #qq
end
GO
注意临时表的名称不要使用select * from sysobjects where name='b' and type='u'
exec dt_path 'a0401'
create table #t(dept varchar(5),parentdept varchar(5))
insert into #t
select 'A0401','A0400' union
select 'A0400','C0300' union
select 'C0300','B0200' union
select 'B0200','0' union
select 'E0501','E0500' union
select 'E0500','E0101'
存储过程
CREATE proc dt_path(@dept varchar(5),@flag int=0) --@flag 默认值为0
as
declare @parentdept varchar(5)
if @flag=0
create table #qq(dept varchar(5))
select @parentdept=parentdept from #t where dept=@dept
if @parentdept<>'0'
begin
insert into #qq select @dept
exec dt_path @parentdept,1
end
else
begin
insert into #qq select @dept
select * from #qq
end
GO
注意临时表的名称不要使用select * from sysobjects where name='b' and type='u'
exec dt_path 'a0401'
- 存储过程实现递归
- 存储过程递归
- 存储过程 递归
- Mysql存储过程递归
- 递归表的删除,存储过程递归
- 存储过程构建递归树.
- DB2递归的存储过程!
- MySQL存储过程递归调用
- mysql存储过程使用递归
- 存储过程实现递归算法
- 一个递归存储过程的例子
- SQL在存储过程中使用递归
- mysql存储过程(递归,交叉表)
- mysql--游标/递归/存储过程/临时表
- oracle存储过程的递归调用
- SQL2005递归查询+存储过程分页
- SQL SERVER 存储过程的天然递归
- oracle存储过程的递归调用
- mount swap 分区
- C标准中一些预定义的宏
- Lua脚本调用C函数小结
- OpenGL的工作步骤和OpenGL命令的语法规则
- 如何穿越防火墙NAT
- 存储过程递归
- DELPHI中的Format函数详解
- xslt元素详解
- 与大家分享——JavaEE5与Glassfish应用服务器。
- 基本A*算法python实现
- .Net 中通用的FormatString格式符整理
- 封闭开发
- 国庆之旅 - 丽江 - Part 4(Terminate)
- ie浏览器对DWR支持的bug~~