首页 > 代码库 > 游标使用-循环语句

游标使用-循环语句

--模型
Declare @MemberID int 
Declare csTemp Cursor For
Select MemberID From xxx
 
Open csTemp
 
Fetch Next From csTemp Into @MemberID
While @@fetch_status=0 
Begin
xxx……
Fetch Next From csTemp Into @MemberID
End
 
Close csTemp
Deallocate csTemp
 
--举例
Declare @MemberID int,@BetCoin money,@AwardCoin money,@IsSystem bit --中奖会员,会员所投,当前奖励金豆数量
   
 
Declare csTemp Cursor For
    Select Distinct MemberID,BetCoin,IsSystem From XyDou_Game_Au11_Bet
    Where WinCoin=0 and Qh=@qh and BetNumber= @result and ( IsSystem=0 or IsSystemGameGoldExchange=1 )
   Open csTemp
   Fetch Next From csTemp Into @MemberID,@BetCoin,@IsSystem
   While @@fetch_status = 0 --如果游标存在
      Begin
    --处理语句.....
    Set @AwardCoin = Round(@BetCoin*@Pv,0,1)
   
    Exec P_Member_ChangeGold_Value ‘游戏‘,@AwardCoin,@MemberID,1
 
 
    Fetch Next From csTemp Into @MemberID,@BetCoin,@IsSystem --跳到下个游标
   End
     
   Close csTemp --关闭游标
   Deallocate csTemp --释放游标