专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »数据库 » sql存储过程递归:存储过程递归实现 »正文

sql存储过程递归:存储过程递归实现

来源: 发布时间:星期四, 2009年2月12日 浏览:41次 评论:0


exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetNodeTable]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[GetNodeTable]
GO

exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tbTest]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tbTest]
GO


CREATE TABLE [dbo].[tbTest] (
[id] [] NULL ,
[upperid] [] NULL ,
[name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) _disibledevent=>select @nodeid=id from tbTest where name=@nodename

declare @nodetable table(nodeid ,nodename varchar(50),nextnodeid )

insert @nodetable select a.id as 'nodeid' ,a.name,a.upperid from tbTest as a where id = @nodeid
while @@rowcount > 0
begin
insert @nodetable
select a.id,a.name,a.upperid
--from tbTest a,@nodetable b
--where a.upperid = b.nodeid and a.id not in(select @nodeid from @nodetable)
from tbTest a,@nodetable b
where a.upperid = b.nodeid and a.id not in(select nodeid from @nodetable)
end
select * from @nodetable

--exec GetNodeTable 1,''

--select * from tbTest

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: