Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 ceiling

Author  Topic 

micnie_2020
Posting Yak Master

232 Posts

Posted - 2012-08-10 : 05:52:49
Hi all,

why my ceiling doesn't return 9.

declare @Months int
set @Months=100
select ceiling(@Months/12)

100/12=8.3333 Output show: 8.

Please advise.

Thank you.

Regards,
Micheale

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-08-10 : 06:03:01
It's called Integer Division.

Try select ceiling(@Months/12E)



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-08-10 : 06:04:37
you are using integer division -- i,e DIV

Example

DECLARE @months INT = 100
DECLARE @divisor INT = 12

SELECT @months / @divisor


Returns 8

Divide by a float or numeric to get the result you want.

DECLARE @months INT = 100
DECLARE @divisor FLOAT = 12

SELECT @months / @divisor

Returns 8.33333333333333

Transact Charlie
Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
http://nosqlsolution.blogspot.co.uk/
Go to Top of Page

micnie_2020
Posting Yak Master

232 Posts

Posted - 2012-08-10 : 06:09:26
Thank you very much.

How can i get just the part of decimal. Output i want is 0.3333.

I want to get the result to tell me 100 months = 8 year & 4 month.

Please advise.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-08-10 : 06:13:31
Use Modula!

SELECT 100 / 12 AS [Years], 100 % 12 AS [Months]


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

micnie_2020
Posting Yak Master

232 Posts

Posted - 2012-08-10 : 07:24:04
Thank you to all.
Go to Top of Page
   

- Advertisement -