Update MS Access database table using update and Aggregrate sum() function

依然范特西╮ 提交于 2021-02-05 09:28:24

问题


I have Two tables in my access database table1(Employee Name,Emp Number,Emp Salary) table2(Employee Name,Emp Number,Total Salary) these tables are related together using "Employee Name" and "Emp Number",How can I update "Total Salary" from table2 with the value Sum(Emp Salary) from first table"


回答1:


Query, which contains aggregated functions or uses queries with aggregated functions is not updateable. So, you can update the data in existing table using:

  1. Temporary table. Save aggregated results in temporary table and then update working table using data from this temporary table.
  2. If aggregating is simple and aggregate query functions can be replaced by domain aggregate functions like DSum or CDount, resulting query will be updateable and you can avoid using temporary tables

Query with domain function may look like this:

UPDATE Result
SET Result.[Total Salary] = DSum("Emp Salary", "Emp", "Employee Name='" & Replace(Result.EmpName, "'", "''") & _
    "' and [Emp Number]=" & Result.[Emp Number])
WHERE Result.[EmpName] = 'Mohan'
    AND Result.[Emp Number] = 1;


来源:https://stackoverflow.com/questions/49583983/update-ms-access-database-table-using-update-and-aggregrate-sum-function

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