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

前端 未结 1 1061
轻奢々
轻奢々 2021-01-27 12:28

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 \"Emp

相关标签:
1条回答
  • 2021-01-27 12:36

    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;
    
    0 讨论(0)
提交回复
热议问题