首页 > 其他 > 详细

游标的使用

时间:2016-01-26 11:55:16      阅读:203      评论:0      收藏:0      [点我收藏+]

DECLARE My_Cursor1 CURSOR --定义游标
FOR (SELECT RowGuid , ProjectRowGuid FROM [BIMPM_Base].[dbo].[ProjectPermission_Role] where SubSystemRowGuid = ‘A9318399-66FE-423E-93F5-CCD7C0A471C4‘) --查出需要的集合放到游标中
OPEN My_Cursor1; --打开游标
declare @RoleRowGuid varchar(50),@ProjectRowGuid varchar(50)
fetch next from My_Cursor1 into @RoleRowGuid,@ProjectRowGuid
while(@@FETCH_STATUS=0)
begin
---内层循环
declare Cursor22 CURSOR for (select RowGuid from [BIMPM_Base].[dbo].[ProjectPermissionItem] where SubSystemRowGuid = ‘A9318399-66FE-423E-93F5-CCD7C0A471C4‘)
OPEN Cursor22
declare @ItemRowGuid varchar(50)
fetch next from Cursor22 into @ItemRowGuid
while(@@FETCH_STATUS=0)
begin
Insert into [BIMPM_Base].[dbo].[ProjectPermission_MenuRole](ProjectRowGuid,PermissionItemRowGuid,RoleRowGuid,SubSystemRowGuid)
values(@ProjectRowGuid,@ItemRowGuid,@RoleRowGuid,‘A9318399-66FE-423E-93F5-CCD7C0A471C4‘)
fetch next from Cursor22 into @ItemRowGuid
end
close Cursor22

fetch next from My_Cursor1 into @RoleRowGuid,@ProjectRowGuid ---移动游标
end
close My_Cursor1

游标的使用

原文:http://www.cnblogs.com/wangzuofei/p/5159500.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!