zl程序教程

您现在的位置是:首页 >  后端

当前栏目

[SQL Server] 循环游标执行-无事务

2023-09-27 14:24:39 时间

From: https://blog.csdn.net/weixin_42609389/article/details/126955029

begin
    declare @a int
    declare @temp varchar(50)
    set @a=1
    
    declare order_cursor cursor for (select [CMID] from [Warehouse].[MT].[Customers])
    
    open order_cursor
    
    fetch next from order_cursor into @temp
        
        while @@FETCH_STATUS = 0    
        begin            
            update [Warehouse].[MT].[Customers] set CMCode=@a where [CMID]=@temp
            set @a=@a+1
            fetch next from order_cursor into @temp   
        end   
    close order_cursor  
    deallocate order_cursor   
end
go