I want some Moore

Blog about stuff and things and stuff...
mostly about SQL server and .Net
posts - 155, comments - 1387, trackbacks - 33

My Links

SQLTeam.com Links

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'm also a MCP and MCTS for SQL Server. 
Welcome to my blog.

Search this Blog
 

My Blog Feed via Email


Get your Google PageRank
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

Feedback

# re: Extended SQL Server Ceiling and Floor functions

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

# re: Extended SQL Server Ceiling and Floor functions

glad you liked it. :)
1/29/2008 1:56 PM | Mladen

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 8 and 2 and type the answer here:

Powered by: