As the question suggests, I need to round up or down to closest 20, with the exception of numbers from 0-14, all must round to 20, because no zero values are allowed.The table has not to be updated with new values.For now I have managed only rounding up or down to the nearest 100 as seen below:
CASE WHEN ROUND(number,-2)=0 THEN CAST(ROUND(number,-2)+100 AS DECIMAL(18, 0))
ELSE CAST(ROUND(number,-2) AS DECIMAL(18,0)) END AS [NUMBER]
Try this:
There may be a more optimal approach, but this was the first solution that came to mind. The
* 1.0is to force conversion to a floating point number so that the/ 20will produce fractional results. The result is rounded usingROUNDthen multiplied back by20to get your final “rounded” value.Edited to take your special case of
0-14into account…