Posts: 13
Threads: 3
Thanks Received:
0 in 0 posts
Thanks Given: 0
Joined: Oct 2023
Reputation:
0
This UPDATE statement will change the a_needMP value in each row of the t_skilllevel table based on the specified conditions.
Simple but effective, feel free to use. Could be used in a similar way to adjust exp, gold and and and...
UPDATE t_skilllevel
SET a_needMP = CASE
WHEN a_needMP >= 500 AND a_needMP <= 750 THEN a_needMP * 0.70
WHEN a_needMP > 750 AND a_needMP <= 1000 THEN a_needMP * 0.50
WHEN a_needMP > 1000 AND a_needMP <= 1500 THEN a_needMP * 0.35
WHEN a_needMP > 1500 AND a_needMP <= 2000 THEN a_needMP * 0.25
WHEN a_needMP > 2000 AND a_needMP <= 3000 THEN a_needMP * 0.17
WHEN a_needMP > 3000 THEN a_needMP * 0.03
ELSE a_needMP
END;
Posts: 29
Threads: 5
Thanks Received:
0 in 0 posts
Thanks Given: 0
Joined: Oct 2022
Reputation:
0
Yess! really nice statement. Only improvement I have is to include comments and use the "between" Like:
UPDATE t_skilllevel
SET a_needMP = CASE
-- Decrease by 30% for values between 500 and 750
WHEN a_needMP BETWEEN 500 AND 750 THEN a_needMP * 0.70
-- Decrease by 50% for values between 751 and 1000
WHEN a_needMP BETWEEN 751 AND 1000 THEN a_needMP * 0.50
-- Decrease by 65% for values between 1001 and 1500
WHEN a_needMP BETWEEN 1001 AND 1500 THEN a_needMP * 0.35
-- Decrease by 75% for values between 1501 and 2000
WHEN a_needMP BETWEEN 1501 AND 2000 THEN a_needMP * 0.25
-- Decrease by 83% for values between 2001 and 3000
WHEN a_needMP BETWEEN 2001 AND 3000 THEN a_needMP * 0.17
-- Decrease by 97% for values greater than 3000
WHEN a_needMP > 3000 THEN a_needMP * 0.03
-- No change for other values
ELSE a_needMP
END;
Basically just explains the logic for the rages. Easier to understand and the use of "between" makes it a bit more readable if you ask me.
Please correct me if I'm wrong!