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 2005 Forums
 Transact-SQL (2005)
 NEXT integer for a division's result

Author  Topic 

fcoreyesv
Starting Member

18 Posts

Posted - 2008-07-29 : 12:39:35
Hi all,

I need a select statement that returns a value based on a length divided by 12. If the value is between .01 and 12 the result should be 1. If the value is between 12.01 and 24 the it should return 2.

In other words it should return the result of the division by 12 but when there is a REMAINDER then the value should go up to the NEXT integer value.

So if the value is 36.5 divided by 12 = 3.0416 the result should be 4.

I am working SQL 2005.

Any suggestions will be greatly appreciated.

Jose Reyes

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-29 : 12:44:59
SELECT cieling(value/12)
Go to Top of Page

fcoreyesv
Starting Member

18 Posts

Posted - 2008-07-29 : 13:20:18
Thanks it works.
I noticed that the value needs to be entered as floating in order to work.
If an integer is entered it does not go UP the next integer.

Select Ceiling (13.0/2)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-29 : 13:33:04
quote:
Originally posted by fcoreyesv

Thanks it works.
I noticed that the value needs to be entered as floating in order to work.
If an integer is entered it does not go UP the next integer.

Select Ceiling (13.0/2)


yup. if your field is integer use like this

Select Ceiling (field * 1.0/2)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-29 : 13:33:34
That's because the result already is integer and there's no decimal to round up.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-30 : 04:05:14
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -