Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql rounding up to a multiple of 5?

Hello i was wondering is there a way to round up to a multiple of 5 in SQL?

For example this only rounds up to ten if i set @Order = 8 or 9 but when it's 7 or 6 it rounds down to 5, i need it to round up to 10 when it's 6 or 7.

declare @Order int

set @Order = 7

select round(cast(@Order as float)/cast(5 as float),0)*5

I need

  • @Order = 1,2,3,4 to round up to 5
  • @Order = 6,7,8,9 to round up to 10
  • @Order = 11,12,13,14 to round up to 15
like image 484
AxV Avatar asked May 16 '13 16:05

AxV


1 Answers

Use the CEILING function

SELECT CEILING(@Order / 5.0) * 5
like image 58
gareththegeek Avatar answered Oct 06 '22 00:10

gareththegeek