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.
| Author |
Topic |
|
daniel50096230
Yak Posting Veteran
99 Posts |
Posted - 2010-12-29 : 09:33:34
|
| Hi all,the following is my table.Total Customer198 8200 6So my total should divide by customer.198/8=24.75200/6=33.33How 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 MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-12-29 : 10:01:31
|
| select cast(1.0*total/customer as decimal(12,0)) from tableMadhivananFailing to plan is Planning to fail |
 |
|
|
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. |
 |
|
|
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 replyMadhivananFailing to plan is Planning to fail |
 |
|
|
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?Jimselect round( (total+.5)/customer,0) ?selectEveryday I learn something that somebody else already knew |
 |
|
|
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 |
 |
|
|
|
|
|