zoukankan      html  css  js  c++  java
  • 通过游标简单实现循环 定时任务

    ALTER proc [dbo].[jtjj]//静态奖金只发一百天
    as
    DECLARE @username varchar(50)
    DECLARE My_Cursor CURSOR --定义游标
    FOR (SELECT w_username FROM wallet) --查出需要的集合放到游标中
    OPEN My_Cursor; --打开游标
    FETCH NEXT FROM My_Cursor INTO @username; --读取第一行数据(将wallet表中的UserId放到@username变量中
    WHILE @@FETCH_STATUS = 0
    begin
    declare @n int
    declare @oldPv decimal(18,2)
    declare @oldcv decimal(18,2)
    select @n=n,@oldPv=w_dzjfPV,@oldcv=w_CV from wallet where w_username=@username
    if @n<=99---------可以继续添加
    begin
    declare @pv decimal(18,2)
    declare @cv decimal(18,2)
    select @pv=dzjf,@cv=rfjfcv from level where id=(select level_Id from [user] where username2=@username)-----从等级表中查出每天该发的奖金
    insert into jtjjjl(jt_username, jt_pv, jt_cv, jt_datetime)values(@username,@pv,@cv,getdate())
    update wallet set w_cv=(@oldcv+@cv),w_dzjfpv=(@oldPv+@pv) ,n=(@n+1) where w_username=@username

    end
    else
    begin
    update [user] set ispayed=0 where username2=@username
    end
    FETCH NEXT FROM My_Cursor INTO @username; --读取下一行数据(将wallet表中的Username放到@Username变量中)

    end

    CLOSE My_Cursor; --关闭游标
    DEALLOCATE My_Cursor; --释放游标

  • 相关阅读:
    UVA 1386 Cellular Automaton
    ZOJ 3331 Process the Tasks
    CodeForces 650B Image Preview
    CodeForces 650A Watchmen
    CodeForces 651B Beautiful Paintings
    CodeForces 651A Joysticks
    HUST 1601 Shepherd
    HUST 1602 Substring
    HUST 1600 Lucky Numbers
    POJ 3991 Seinfeld
  • 原文地址:https://www.cnblogs.com/cdaq/p/3424730.html
Copyright © 2011-2022 走看看