using nested if in stored procedure

旧巷老猫 提交于 2019-12-13 05:14:22

问题


I am trying to create a stored procedure using nested if, but I am not getting how to frame it. Please help me out. This if what I am trying to do:

CREATE PROCEDURE StarDistributorProfit 
@sponsorId varchar(20),

AS
if exists(select sponsor_id where(select count(user_id) from usertransaction where bv=50001))
    if count=1,TotalGBV=25000,TotalPBV=200
BEGIN
update usertransaction set rank='executive' where sponsor_id=@sponsorId
update usertransaction set dp=(0.309*BV)
update usertransaction set leadership_bonus=(0.07*BV)
END
if count=2,TotalGBV=20000,TotalPBV=200
BEGIN
update usertransaction set rank='star executive' where sponsor_id=@sponsorId
update usertransaction set dp=(0.318*BV)
update usertransaction set leadership_bonus=(0.03*BV)
END
if count=3,TotalGBV=20000,TotalPBV=300
BEGIN
update usertransaction set rank='Organizer' where sponsor_id=@sponsorId
update usertransaction set dp=(0.318*BV)
update usertransaction set leadership_bonus=(0.03*BV)
END 
GO

回答1:


Seems you are looking for AND operator...

For example IF count=1 AND TotalGBV=25000 AND TotalPBV=200.




回答2:


If you want to check multiple conditions, use AND between them - not a comma:

IF count = 1 AND TotalGBV = 25000 AND TotalPBV = 200
BEGIN
   UPDATE usertransaction SET rank = 'executive' WHERE sponsor_id = @sponsorId
   UPDATE usertransaction SET dp = (0.309 * BV)
   UPDATE usertransaction SET leadership_bonus = (0.07*BV)
END
-- and so forth for all your IF^s 


来源:https://stackoverflow.com/questions/26038976/using-nested-if-in-stored-procedure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!