sql存储过程递归:存储过程递归实现来源: 发布时间:星期四, 2009年2月12日 浏览:41次 评论:0
![]() drop procedure [dbo].[GetNodeTable] GO ![]() drop table [dbo].[tbTest] GO CREATE TABLE [dbo].[tbTest] ( [id] [ ![]() [upperid] [ ![]() [name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ) _disibledevent=>select @nodeid=id from tbTest where name=@nodename declare @nodetable table(nodeid ![]() ![]() 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
相关文章读者评论发表评论 |