admin管理员组文章数量:1032818
递归存储过程中使用cursor
注意定义成local类型的cursor !
PROCEDURE sp_get_all_lineal_parent @node_id int, @lineal_path varchar(200) output with encryption AS
SET NOCOUNT ON BEGIN IF ISNULL(@lineal_path, 'NULL') = 'NULL' SET @lineal_path = '' IF EXISTS( select DependentProductID from Dependence_TB where ProductID = @node_id ) BEGIN DECLARE cur_parent_node CURSOR FAST_FORWARD local FOR SELECT DependentProductID FROM Dependence_TB WHERE ProductID = @node_id
DECLARE @parent_node_id int
OPEN cur_parent_node FETCH NEXT FROM cur_parent_node INTO @parent_node_id WHILE @@FETCH_STATUS = 0 BEGIN set @lineal_path = @lineal_path + ',' + cast(@parent_node_id as varchar) exec sp_get_all_lineal_parent @parent_node_id, @lineal_path output
FETCH NEXT FROM cur_parent_node INTO @parent_node_id END CLOSE cur_parent_node DEALLOCATE cur_parent_node END insert into ##temp_a(a) select 100 select * from ##temp_a END
--调用示例begin declare @path varchar(200) create table ##temp_a(a int) EXEC sp_get_all_lineal_parent 12, @path output drop table ##temp_a select @path end
kitesky
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2008-10-28,如有侵权请联系 cloudcommunity@tencent 删除cursorparentpath存储过程递归递归存储过程中使用cursor
注意定义成local类型的cursor !
PROCEDURE sp_get_all_lineal_parent @node_id int, @lineal_path varchar(200) output with encryption AS
SET NOCOUNT ON BEGIN IF ISNULL(@lineal_path, 'NULL') = 'NULL' SET @lineal_path = '' IF EXISTS( select DependentProductID from Dependence_TB where ProductID = @node_id ) BEGIN DECLARE cur_parent_node CURSOR FAST_FORWARD local FOR SELECT DependentProductID FROM Dependence_TB WHERE ProductID = @node_id
DECLARE @parent_node_id int
OPEN cur_parent_node FETCH NEXT FROM cur_parent_node INTO @parent_node_id WHILE @@FETCH_STATUS = 0 BEGIN set @lineal_path = @lineal_path + ',' + cast(@parent_node_id as varchar) exec sp_get_all_lineal_parent @parent_node_id, @lineal_path output
FETCH NEXT FROM cur_parent_node INTO @parent_node_id END CLOSE cur_parent_node DEALLOCATE cur_parent_node END insert into ##temp_a(a) select 100 select * from ##temp_a END
--调用示例begin declare @path varchar(200) create table ##temp_a(a int) EXEC sp_get_all_lineal_parent 12, @path output drop table ##temp_a select @path end
kitesky
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2008-10-28,如有侵权请联系 cloudcommunity@tencent 删除cursorparentpath存储过程递归本文标签: 递归存储过程中使用cursor
版权声明:本文标题:递归存储过程中使用cursor 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/jiaocheng/1747967718a2235050.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论