Operation must use an updatable query

孤街浪徒 提交于 2020-01-16 04:17:52

问题


I am trying to update a column in one table to set its value to the count of records in another table. This produces the error:

Operation must use an updateable query.

Query:

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

It seems Access does not like the Select Count(*) from Batch sub-query. If I replace it with a literal value, it works fine.

Any suggestions to resolve this issue is much appreciated.


回答1:


Unfortunately this is an inherent restriction of the JET database engine used by MS Access: no part of an update query may use aggregation, else the resulting recordset is not updateable.


There are a couple of workarounds:

You can use a domain aggregate function, such as DCount:

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

Alternatively, you can use a temporary table to store the result of the count, and then update the records using the value held in the table, e.g.

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


来源:https://stackoverflow.com/questions/57124762/operation-must-use-an-updatable-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!