views:

69

answers:

4

I would like to get 50 as the output instead of 0.

+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
A: 

It is probably doing integer division on the 1/2, evaluating it as 0, so then the whole statement is zero.

cohensh
+7  A: 

It's because of integer division; 1/2 = 0, 0 * 100 = 0.

Use 1/2.0 * 100 instead

NullUserException
or swap the order of multiplication and division: 1 * 100 / 2
Toad
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