2012-11-06 20 views
1

以下是我設置:數據庫的計算是錯誤的

result = price/(case when tax = 0 then @tax1h/100 else @tax2/100 end + 1) 

這些值:

price = 17.5 
tax = 1 
tax2 = 6 

17.5 /(6/100 + 1)= 16.5

而且這返回17.5爲什麼會發生這種情況,以及如何解決它?

回答

6

Integer division

select (6/100 + 1) 

的上面的結果爲1

然而,結果:

select (6/100.0 + 1) 

是1.06。