开发者

Why does query select (1/2) * 100 return 0 instead of 50 in SQL server 2005

I would like开发者_如何学Go to get 50 as the output instead of 0.


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

Use 1/2.0 * 100 instead


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.


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


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜