积分等级的存储过程


exec setScores 'test','test'


alter proc setScores (@userName varchar(120),@password varchar(120))
as
begin
declare @count int
declare @lastDate datetime
declare @gid varchar(60)
declare @sum int
declare @level varchar(60)
---年度变量
declare @regDate datetime
declare @yearCount int
---函数主题
select @gid=Gid from CusUsers where [User_Name]=@userName
select @count=count(1) from CusUsers where [User_Name]=@userName and User_Pass=@password
if(@count>0)
begin
select @lastDate=gdate from UserScrores where uid=@gid and stype=1 order by gdate desc
set @lastDate=isnull(@lastDate,getdate()-1)
if(datediff(day,@lastDate,getdate())>=1)
begin
--添加登陆日志
insert into UserScrores(stype,uid,Scores) select '1',@gid,10

end
--年度分设置
select @regDate=Gdate from CusUsers where  Gid=@gid
set @yearCount=datediff(year,@regDate,getdate())
if(@yearCount>=0)
begin
print '10'
update UserScrores set Scores=50 where uid=@gid and stype=10
if(@@rowcount<=0)
insert into UserScrores(stype,uid,Scores) select '10',@gid,50
end
else if (@yearCount>=1 and @yearCount<=2)
begin
update UserScrores set Scores=50 where uid=@gid and stype=11
if(@@rowcount<=0)
insert into UserScrores(stype,uid,Scores) select '11',@gid,50
end
else if(@yearCount>=3)
begin
update UserScrores set Scores=50 where uid=@gid and stype=12
if(@@rowcount<=0)
insert into UserScrores(stype,uid,Scores) select '12',@gid,50
end

---设置级别
select @sum=sum(isnull(Scores,0)) from UserScrores where uid=@gid
select @level=levelMark from LevelTable where @sum between SStart and SEnd
update CusUsers set ULevel=@level where Gid=@gid
--设置结束
end

end

GO


select * from LevelTable

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值