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
 General SQL Server Forums
 New to SQL Server Programming
 Total Divide

Author  Topic 

daniel50096230
Yak Posting Veteran

99 Posts

Posted - 2010-12-29 : 09:33:34
Hi all,

the following is my table.

Total Customer
198 8
200 6

So my total should divide by customer.

198/8=24.75
200/6=33.33

How can I calculate this so that if the decimal greater than 5 then should increase one and if less than then should remain the same.

For example, the total 24.75 should increase to 25 and 33.33 should be 33.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-12-29 : 09:53:46
just cast it to integer

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-12-29 : 10:01:31
select cast(1.0*total/customer as decimal(12,0)) from table

Madhivanan

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

daniel50096230
Yak Posting Veteran

99 Posts

Posted - 2010-12-29 : 10:01:54
Any sample on cast? Because I am not too sure on cast.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-12-29 : 10:05:56
quote:
Originally posted by daniel50096230

Any sample on cast? Because I am not too sure on cast.


See my previous reply

Madhivanan

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

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-12-29 : 10:14:21
Doesn't select cast(1.0*total/customer as decimal(12,0)) from table round up on >= 5, and not just > 5?

Jim


select round( (total+.5)/customer,0) ?

select

Everyday I learn something that somebody else already knew
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-12-29 : 11:33:21
[code]select
amt,
amt_rounded = round(amt,0),
amt_rounded_integer = convert(int,round(amt,0))
from
( -- Test data
select amt = 24.00 union all
select amt = 24.49 union all
select amt = 24.50 union all
select amt = 24.99
) a[/code]
Results:
[code]amt amt_rounded amt_rounded_integer
------ ----------- -------------------
24.00 24.00 24
24.49 24.00 24
24.50 25.00 25
24.99 25.00 25 [/code]

CODO ERGO SUM
Go to Top of Page
   

- Advertisement -