Wednesday, August 29, 2007

RoundUP

How to round up any number.


Create function :

CREATE FUNCTION dbo.RoundUP(@Value float )RETURNS int AS
BEGIN
DECLARE @Result int
SELECT @Result = ROUND(@Value,0)
IF @Result < @Value SET @Result = @Result + 1 RETURN @Result END Test :

select dbo.RoundUp(124.000001) as result

Result :

4 comments:

PP said...

Works great and it's clear.
Thanks

Unknown said...

Just a tip you can use the MS SQL function 'Ceiling' to do a very similar thing (which was easier in my case)
Thanks for the tip!

set said...

Thanks so much, James :) that is esiest way.

I've never known before.
I just use sql function which I know and I could't find any solution.

set said...

Easiest way.

SELECT CEILING(20.0001 )

Result is 21