Round *UP* to the nearest 100 in SQL Server

后端 未结 13 1029
野性不改
野性不改 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:38

    There's no native function that will do this, but there are any number of simple math tricks that will. An example:

    DECLARE @Foo int
    SET @Foo = 720
    
    print @Foo
    print (@Foo + 100) % 100
    PRINT @Foo - (@Foo + 100) % 100
    

提交回复
热议问题