I want some Moore

Blog about stuff and things and stuff. Mostly about SQL server and .Net
posts - 219, comments - 2287, trackbacks - 33

My Links

Advertisement

News

Hi! My name is 
Mladen Prajdić  I'm from Slovenia and I'm currently working as a .Net (C#) and SQL Server developer.

I also speak at local user group meetings and conferences like SQLBits and NT Conference
Welcome to my blog.
SQL Server MVP

My Books

SQL Server MVP Deep Dives 2
The Red Gate Guide to SQL Server Team based Development Free e-book

My Blog Feed via Email
Follow MladenPrajdic on Twitter


Users Online: who's online

Article Categories

Archives

Post Categories

Cool software

Other Blogs

Other stuff

SQL stuff

Extended SQL Server Ceiling and Floor functions

Maybe i'm reinventing hot water but no matter. It's fun for me :)))
These 2 functions round the number up or down on the decimal position we specify.

create

function dbo.FloorEx(@num decimal(38, 33), @decimalPosition int)

returns

decimal(38, 33)

as

begin

if

 

@decimalPosition < 0 set @decimalPosition = 0

return

floor(@num*power(10, @decimalPosition))/power(10, @decimalPosition)

end

go

create

function dbo.CeilingEx(@num decimal(38, 33), @decimalPosition int)

returns

decimal(38, 33)

as

begin

if

 

@decimalPosition < 0 set @decimalPosition = 0

return

ceiling(@num*power(10, @decimalPosition))/power(10, @decimalPosition)

end

go

 

declare

select

@num decimal(38, 33), @decimalPosition int @num = 10.123456, @decimalPosition = 3

select

dbo

dbo

go

@num, .FloorEx(@num , @decimalPosition), .CeilingEx(@num , @decimalPosition)

drop

function dbo.FloorEx

drop

function dbo.CeilingEx

Print | posted on Wednesday, April 05, 2006 9:59 AM | Filed Under [ SQL Server ]

Feedback

Gravatar

# re: Extended SQL Server Ceiling and Floor functions

Thanks, you saved me
1/29/2008 1:55 PM | Christos
Gravatar

# re: Extended SQL Server Ceiling and Floor functions

glad you liked it. :)
1/29/2008 1:56 PM | Mladen
Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET