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 |
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2006-06-08 : 03:17:58
|
| Hi,Please see why @X1 returns 0 whereas it should return a value of 50.Thanksdeclare @A1 intdeclare @A2 intdeclare @A3 intdeclare @B1 intdeclare @B2 intdeclare @B3 intdeclare @X1 intset @A2 = 5set @A3 = 5set @B2 = 3set @B3 = 2select (@B2+@B3)select (@A2+@A3)set @X1=((@B2+@B3)/(@A2+@A3))*100select @X1 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-06-08 : 03:35:35
|
| Useset @X1=((@B2+@B3)*1.0/(@A2+@A3))*100MadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-06-08 : 03:35:51
|
integer divide by integer = integerso 5 / 10 = 0change to set @X1=((@B2+@B3)*100/(@A2+@A3)) KH |
 |
|
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2006-06-08 : 03:41:13
|
| How about this?set @X1=(convert(decimal, @B2+@B3)/convert(decimal, @A2+@A3))*100orset @X1=(convert(float, @B2+@B3)/convert(float, @A2+@A3))*100Thanks |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-06-08 : 03:43:26
|
use decimal. float is approximate value (unless you want this) KH |
 |
|
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2006-06-08 : 04:11:20
|
| Solved.Thanks |
 |
|
|
|
|
|