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; --释放游标