2013-09-24 178 views
0

我想在執行兩階段貨幣轉換的訪問中運行查詢。 它從交易貨幣的匯率表中獲得匯率,然後計算該地區的匯率。訪問查詢與多個where子句

有沒有辦法在一個查詢中做到這一點。我在下面嘗試,但得到語法錯誤。

UPDATE REPORT 
SET REPORT.[Conversion Rate] = 
(

(
Exchange_Rates.Rate 
Where 
Exchange_Rates.code = REPORT.[Transaction Currency Code] 
) 

/

(
Exchange_Rates.Rate 
Where 
Exchange_Rates.code = REPORT.[Regional Currency Code] 
) 

) 

回答

0

您可以使用訪問UPDATE JOIN語法匯率表連接到報告表:

UPDATE (Report 
     INNER JOIN Exchange_Rates tr 
      ON tr.code = Report.[Transaction Currency Code]) 
     INNER JOIN Exchange_rates reg 
      ON reg.code = report.[Regional Currency Code] 
SET  [Conversion Rate] = tr.Rate/reg.Rate; 

注:你需要加入兩次,同時獲得匯率

另一種選擇是使用DLOOKUP功能:

UPDATE REPORT 
SET  [Conversion Rate] = Dlookup("Rate", "Exchange_Rate", "Code = " & Report.[Transaction Currency Code]) 
          /
          Dlookup("Rate", "Exchange_Rate", "Code = " & Report.[Regional Currency Code]) 
+0

由於內部聯接完美的伎倆。 –