合并多个更新查询

时间:2014-01-20 22:10:05

标签: tsql updates

如何组合这两个查询(使用crosstables和条件进行更新)以减少在宏中使用许多查询的需要?

查询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"));

1 个答案:

答案 0 :(得分: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");