Search code examples
sql-server-2008

Round to nearest 5 in SQL Server


I have a Money column in my SQL Server 2008 table. In my below query how can I round it to nearest 5$

select FineAmount from tickets

Thanks


Solution

  • select round(FineAmount*2,-1)/2 from tickets
    

    or to put nicholaides suggestion in sql

    select round(FineAmount/5.0,0)*5 from tickets
    

    The example assumes that FineAmount is of type money. The second approach is probably better as the first one works with the limit of maximum_value_of_money_type/2

    More on ROUND