Round *UP* to the nearest 100 in SQL Server

后端 未结 13 955
野性不改
野性不改 2020-12-25 11:18

Is it possible to easily round a figure up to the nearest 100 (or 1000, 500, 200 etc.) in SQL Server?

So:

720 -> 800
790 -> 800
1401 -> 1500

相关标签:
13条回答
  • 2020-12-25 11:52

    You can use this code, assuming your amount is an int. If not you will need to cast, so you get integer division.

    If amount % 100 != 0 Then
       roundedAmount = ((amount / 100) * 100) + 100
    Else
       roundedAmount = amount
    

    You might want to package this into a user defined function.

    0 讨论(0)
提交回复
热议问题