Fork me on GitHub

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--打开游标
     BEGIN
--从集合种取值 FETCH NEXT FROM authors_cur_product INTO @iChildid,@cInvcode,@iQuantity --循环 WHILE @@fetch_status=0 BEGIN --逻辑代码
      FETCH NEXT FROM authors_cur_product   INTO  @iChildid,@cInvcode,@iQuantity
         END  
         
         END --CLOSE authors_cur_product
       CLOSE authors_cur_product--关闭游标
       DEALLOCATE authors_cur_product --回收内存

 

posted @ 2020-09-20 19:19  HelloLLLLL  阅读(144)  评论(0编辑  收藏  举报