我想查看,如果赞助商的用户名为TotalBV >= 50001
,则赞助商的Rank, DP, Leadership_Bonus
将使用特定值进行更新
如果赞助商有1个用户TotalBV >= 50001
,则使用第一个案例陈述中的值更新他的记录。
如果赞助商有2个用户TotalBV >= 50001
,那么用第二个案例陈述中的值更新他的记录......等等
这是我到目前为止所做的,但我在更新声明中遇到错误:
declare @UserId varchar(50),@myInt int,@SponsorId varchar(50),@Rank varchar(50),@dp int,@LB int
declare c1 cursor READ_ONLY
for
set @myInt = (select COUNT(User_Id) from UserTransaction as count where @SponsorId='RL9058' and TotalBV>=50001)
open c1
fetch next from c1
into @SponsorId,@UserId,@Rank
while @@FETCH_STATUS=0
BEGIN
update UserTransaction set Rank,DP,Leadership_Bonus=(case
when (@myInt=1 and TotalGBV=25000 and TotalPBV=200) then (Rank='executive' and DP=(0.309*BV) and Leadership_Bonus=(0.07*BV))
when (@myInt=2 and TotalGBV=20000 and TotalPBV=200) then (rank='star executive' and dp=(0.318*BV) and leadership_bonus=(0.03*BV))
when (@myInt=3 and TotalGBV=20000 and TotalPBV=300) then (rank='Organizer' and dp=(0.327*BV) and leadership_bonus=(0.02*BV))
when (@myInt=4 and TotalGBV=15000 and TotalPBV=300) then (rank='Star Organizer' and dp=(0.336*BV) and leadership_bonus=(0.01*BV))
when (@myInt=5 and TotalGBV=15000 and TotalPBV=500) then (rank='Co-Ordinater' and dp=(0.345*BV) and leadership_bonus=(0.01*BV))
when (@myInt=6 and TotalGBV=10000 and TotalPBV=500) then (rank='Star Co-Ordinater' and dp=(0.354*BV) and leadership_bonus=(0.01*BV))
when (@myInt=7 and TotalGBV=10000 and TotalPBV=1000) then (rank='7Star Co-Ordinater' and dp=(0.360*BV) and leadership_bonus=(0.01*BV))
else null end)
where @SponsorId='RL9058'
FETCH NEXT FROM c1
into @UserId,@SponsorId,@Rank,@dp,@LB
END
close c1
DEALLOCATE c1