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)
 help rounding up

Author  Topic 

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2009-03-05 : 03:19:49
Hi,

I have a statement in which I am trying to round UP. If there is any remainder I want to round up, not sure if there is a function in SQL for this ? I tried CEILING but its not exactly what I need.

(21 / 20) = 2

(41 / 20) = 3

(49 / 20) = 3

(20 /20) = 1


any help much appreciated!

Thanks again!
mike123

ddramireddy
Yak Posting Veteran

81 Posts

Posted - 2009-03-05 : 03:23:01
just add 19 to that number and divide with 20, its enough.
select (@Number + 19) / 20
Go to Top of Page

asgast
Posting Yak Master

149 Posts

Posted - 2009-03-05 : 04:01:10
SELECT @a/@b + CASE WHEN @a % @b > 0 THEN 1 ELSE 0 end;
Go to Top of Page

ayamas
Aged Yak Warrior

552 Posts

Posted - 2009-03-05 : 05:45:39

select (21 * 1.0 / 20)
select (41 * 1.0 / 20)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-05 : 06:11:21
Is this related to this topic?
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=121029



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

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-03-05 : 07:01:07
cieling works once check the results of below statements

select ceiling(21*1.0/20)
select ceiling(41*1.0/20)
select ceiling(49*1.0/20)
select ceiling(20*1.0/20)

Jai Krishna
Go to Top of Page
   

- Advertisement -