I am trying to round down the value to the nearest 50. 1-50 it should round down to below 00 and when its 51-rest then it should round down to 50
ex:
I tried this,its wrking good but I need smething other than case statement
@ResultAmount = ROUND(@ResultAmount, -2, 1) +
CASE WHEN RIGHT(CONVERT(INT, FLOOR(@ResultAmount)), 2) IN (00, 50)
THEN RIGHT(CONVERT(INT, FLOOR(@ResultAmount)), 2)
WHEN RIGHT(CONVERT(INT, FLOOR(@ResultAmount)), 2) BETWEEN 1 AND 49
THEN 00
WHEN RIGHT(CONVERT(INT, FLOOR(@ResultAmount)), 2) BETWEEN 51 AND 99
THEN 50
END
Thanks in advance!!!
This is all you need
SELECT FLOOR(@ResultAmount / 50) * 50;
e.g below
declare @ResultAmount decimal(10,2) = 249;
SELECT FLOOR(@ResultAmount / 50) * 50;
SET @ResultAmount = 250;
SELECT FLOOR(@ResultAmount / 50) * 50;
SET @ResultAmount = 200;
SELECT FLOOR(@ResultAmount / 50) * 50;
SET @ResultAmount = 199;
SELECT FLOOR(@ResultAmount / 50) * 50;
It sounds like numbers 0-50 get rounded up to "50", but any number larger than that should just get rounded to the nearest 50. Something like the following should work:
(CASE WHEN f1/50 < 1 THEN 1 ELSE ceiling(f1/50) END) * 50 AS rounded_to_50
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With