2014-01-20 66 views
0

如何組合這兩個查詢(使用交叉表和條件進行更新)以減輕在宏內使用多個查詢的需要?合併多個更新查詢

查詢1個

UPDATE [Master Output Table], [Input table] SET [Master Output Table].[Area Change Ar Transfer From] = [Input table]![Amount 1723] 
WHERE ((([Input table]![Transaction Type 1723])="Area Change Ar Transfer From") AND (([Master Output Table]![Transaction Type])="Amount 1723")); 

查詢2

UPDATE [Master Output Table], [Input table] SET [Master Output Table].[Area Change Ar Transfer From] = [Input table]![Tax Amount 1723] 
WHERE ((([Input table]![Transaction Type 1723])="Area Change Ar Transfer From") AND (([Master Output Table]![Transaction Type])="Tax Amount 1723")); 

回答

0

這應該爲你工作。

UPDATE [Master Output Table], [Input table] 
SET 
[Master Output Table].[Area Change Ar Transfer From] = 
    case when [Master Output Table]![Transaction Type]="Amount 1723" then 
    [Input table]![Amount 1723] 
    else 
    [Input table]![Tax Amount 1723] 
end 
WHERE 
[Input table]![Transaction Type 1723]="Area Change Ar Transfer From" 
AND 
[Master Output Table]![Transaction Type] in ("Amount 1723","Tax Amount 1723"); 
+0

我得到一個語法錯誤(缺少操作符),它似乎與以'case when'開頭的部分綁定在一起, – user3204048