I would like to get 50 as the output instead of 0.
views:
69answers:
4
+1
A:
This is likely because SQL Server is using integer arithmetic for the calculation. The integer part of 1/2 is 0, and 0 * 100 = 0.
ggg
2010-08-09 06:22:17
A:
It is probably doing integer division on the 1/2, evaluating it as 0, so then the whole statement is zero.
cohensh
2010-08-09 06:22:40
+7
A:
It's because of integer division; 1/2 = 0
, 0 * 100 = 0
.
Use 1/2.0 * 100
instead
NullUserException
2010-08-09 06:24:06
or swap the order of multiplication and division: 1 * 100 / 2
Toad
2010-08-09 06:55:08
A:
The same in C#, Java and VB.net at least: integer arithmetic.
Why do you expect SQL be any different in evaluating expressions to other languages?
gbn
2010-08-09 06:50:08