讓假設我有兩個表選擇數據
- 稅
- 產品
我要選擇的產品值乘以稅各自的增值稅值的總和表格的百分比,其中產品的日期小於稅收日期且mDate
小於產品日期,按增值稅分組或ttid
例如
Taxes products
ttid date value mDate Vat value date
0 02-06-11 20 03-07-11 0 15 01-07-11
1 03-07-11 10 03-08-11 0 15 01-07-11
0 03-07-11 14 03-08-11 0 15 02-08-11
1 03-08-11 15 03-09-11 1 10 04-07-11
1 10 06-08-11
1 10 08-09-11 --this will not include
所以我的結果看起來像這樣。
TTId Value
0 3+3+2.1=8.1
1 1.5+1=2.5
我到目前爲止寫的查詢。
select sum
(
(cast(t.Value as float)
*
(cast(x.value as float)/100)
)
as 'Vat'
,x.ttid
from prducts t
,taxes x where x.ttid=t.vat and x.mDate>t.date and x.date<=t.date
group by x.ttid
有人能幫助我嗎?
假設增值稅和所得稅的這些會談是指一個或多個這些金額是貨幣,請不要使用float - 使用[十進制](http://msdn.microsoft.com/en-us/庫/ ms187746.aspx)以合適的比例和精度。 –
你能檢查你的SUM計算嗎?您有+後跟* – gbn