操作必须使用可更新的查询

Operation must use an updatable query

我正在尝试更新一个 table 中的列,以将其值设置为另一个 table 中的记录数。这会产生错误:

Operation must use an updateable query.

查询:

UPDATE Tracking SET BatchCount = (Select Count(*) from Batch)
WHERE ReportingDate=Date();

Access 似乎不喜欢 Select Count(*) from Batch 子查询。如果我用文字值替换它,它工作正常。

非常感谢任何解决此问题的建议。

不幸的是,这是 MS Access 使用的 JET 数据库引擎的固有限制:update 查询的任何部分都不能使用聚合,否则生成的记录集不可更新。


有几个解决方法:

您可以使用域聚合函数,例如DCount:

update tracking set batchcount = dcount("*", "Batch")
where reportingdate = date();

或者,您可以使用临时 table 来存储计数结果,然后使用 table 中保存的值更新记录,例如

select count(*) as cnt into temptable from batch
update tracking, temptable set tracking.batchcount = temptable.cnt
where tracking.reportingdate = date();