sqlserver游标的使用

SET @iChildid=0
       DECLARE authors_cur_product CURSOR FOR  --为一个数据集合定义游标
         SELECT idid,Swap_rdrecords10.cinvcode,iQuantity FROM Swap_rdrecords10 
         INNER JOIN Inventory ON Swap_rdrecords10.cInvCode=Inventory.cInvCode
          WHERE Swap_rdrecords10.mescode=@cVouchCode AND Inventory.bSerial=1
       OPEN authors_cur_product--打开游标
       --从集合种取值
       FETCH NEXT FROM authors_cur_product INTO @iChildid,@cInvcode,@iQuantity
      --循环
        WHILE @@fetch_status=0
         BEGIN  
          --逻辑代码
              END  
         FETCH NEXT FROM authors_cur_product   INTO  @iChildid,@cInvcode,@iQuantity
         END --CLOSE authors_cur_product
       CLOSE authors_cur_product--关闭游标
       DEALLOCATE authors_cur_product --回收内存
原文地址:https://www.cnblogs.com/HelloQLQ/p/13701633.html