USE [chy]
GO
/****** Object: StoredProcedure [dbo].[jtjj] Script Date: 02/22/2014 10:39:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
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,state=0 where username2=@username
end
FETCH NEXT FROM My_Cursor INTO @username; –读取下一行数据(将wallet表中的Username放到@Username变量中)
end
CLOSE My_Cursor; –关闭游标
DEALLOCATE My_Cursor; –释放游标