Use Aggregate functions in a update query

J

Jose.M.Huerta

I want to pre-compute the sum of some values and store it on a table.
The query is:

UPDATE tblMachacas AS t1 SET Participacion = (SELECT Sum([Valor]) FROM
tblDefsTurno INNER JOIN tblTurnos ON tblDefsTurno.IdDefTurno =
tblTurnos.IdDefTurno
WHERE tblTurnos.IdMachaca = t1.IdMachaca);

In the table tblMachacas I have a field called Participacion that is
the sum of valor in all related registers of tblDefsTurno. But I get
the next error in access:

"La operación debe usar una consulta actualizable" -> The operation
must use an updatable query.

tblMachacas is a linked table and I can update it using:

UPDATE tblMachacas SET Participacion = 0 WHERE IdMachaca = 1;

How can I do it?
 
A

Allen Browne

Try a DSum():
UPDATE tblMachacas SET Participacion =
DSum("Valor", "Query1", "IdMachaca = " & [IdMachaca]);

Assumes Query1 has the 2 tables JOINed.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

I want to pre-compute the sum of some values and store it on a table.
The query is:

UPDATE tblMachacas AS t1 SET Participacion = (SELECT Sum([Valor]) FROM
tblDefsTurno INNER JOIN tblTurnos ON tblDefsTurno.IdDefTurno =
tblTurnos.IdDefTurno
WHERE tblTurnos.IdMachaca = t1.IdMachaca);

In the table tblMachacas I have a field called Participacion that is
the sum of valor in all related registers of tblDefsTurno. But I get
the next error in access:

"La operación debe usar una consulta actualizable" -> The operation
must use an updatable query.

tblMachacas is a linked table and I can update it using:

UPDATE tblMachacas SET Participacion = 0 WHERE IdMachaca = 1;

How can I do it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top