Though not as cool a solution as Mr. Lange's tally table, this alternative is more math oriented than set oriented and is very fast. Plus you could easily turn this into a SP passing any value that you want to round to. NOTE: I borrowed Mr. Lange's cte to demo the solution. (Thank-you!)
;with MyData (MyValue, Target) as
(
select 0.5, 5 union all
select 1.0, 5 union all
select 2.0, 5 union all
select 5, 5 union all
select 5.75, 5 union all
select 8, 10 union all
select 11, 15 union all
select 50, 50 union all
select 50.5, 50 union all
select 50.75, 50 union all
select 51, 55 union all
select 54.99, 55 union all
select 86.5, 90
)
Select d.MyValue, d.Target,
case when d.MyValue % 5 < 1 then FLOOR(d.MyValue)
when d.MyValue % 5 < 3 then FLOOR ((d.MyValue + (5.0 / 2.0)) / 5) * 5.0 + 5.0
else FLOOR((d.MyValue + (5.0 / 2.0)) / 5) * 5.0
end as Result
from MyData d
The case statement was required because you are rounding UP to the nearest 5, not just to the nearest 5.
__________________________________________________________________________________________________________
How to Post to get the most: http://www.sqlservercentral.com/articles/Best+Practices/61537/