How can we achieve excel ceiling function with significance value in SQL Server

Viewed 90

How can we apply excel ceiling function with significance value in SQL server ?

=Ceiling(10,3) 

it should return 12, because 12 is roundup nearest to 3

=Ceiling(36,7) 

it should return 42, because 42 is roundup nearest to 7

More examples: https://i.stack.imgur.com/kSDYI.png

1 Answers

You can use arithmetic:

select ceiling(10 * 1.0 / 3) * 3

The 1.0 is to avoid integer division. If the value is numeric or float, then it is not needed.

Here is a db<>fiddle.

Related