码迷,mamicode.com
首页 > 其他好文 > 详细

游标的使用

时间:2016-01-26 11:58:33      阅读:116      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!