Hi
John Spencer said:
Normally, you use something like
UPDATE MyTable INNER JOIN MyQuery
ON MyTable.ID = MyQuery.ID
SET MyTable.F01 = [MyQuery].[F01]
, MyTable.F02 = [MyQuery].[F02]
, MyTable.F03 = [MyQuery].[F03]
That will work in most cases, however if MyQuery uses sum, avg, min, max,
etc functions this will fail with an error about you must use an
updateable query.
It explains it all! MyQuery is an aggregate query
As it will be too much work to edit all queries to look more simple, I'll
copy real stuff here
I have tables
tblKoristaja: TabN (Primary, Text), ..., H01, H02, ..., H012, ... . It
contains a list of people/employees, and there are 12 columns (H01-H12)
where current estimated working hours for 12 months are stored - those same
columns I want to update.
tblTegevus: TegevusID (Primary, Autonumeric), ..., M01, M02, ..., M012. It
contains a list of possible actions for people, and how many times in month
those actions are performed for 12 months.
tblPindTegevus: PindTegevusID (Primary, Autonumeric), PindID (Long Integer),
TegevusID (Long Integer), Tunnid, Minutid. It links actions (TegevusID) with
Objects (PindID), and stores estimated time - hours (Tunnid) and minutes
(Minutid) - reserved for those actions.
tblPindTegevusKoristaja: ID (Primary, Autonumeric), PindID (Long Integer),
TegevusID (Long Integer), TabN (Text), Alates (Date). It links people (Tabn)
with actions on objects (PindID, TegevusID), starting from certain date
(Alates) - i.e. the table contains the history of attached actions for
people. (When some action remains unattached from some time moment, there
will be according record in tblPindTegevusKoristaja with this date, where
TabN=Null)
Now I need to run a procedure which recalculates all H01-H12 in tblKoristaja
with currently estimated monthly hours.
Those hours I can calculate with query qCurrKoristajaTunnid (this is MyQuery
in my earlier post):
SELECT tblKoristaja.TabN, Sum(qCurrKoristajaTegevused.Tunnid*tblTegevus.M01)
AS H01, Sum(qCurrKoristajaTegevused.Tunnid*tblTegevus.M02) AS H02,
Sum(qCurrKoristajaTegevused.Tunnid*tblTegevus.M03) AS H03,
Sum(qCurrKoristajaTegevused.Tunnid*tblTegevus.M04) AS H04,
Sum(qCurrKoristajaTegevused.Tunnid*tblTegevus.M05) AS H05,
Sum(qCurrKoristajaTegevused.Tunnid*tblTegevus.M06) AS H06,
Sum(qCurrKoristajaTegevused.Tunnid*tblTegevus.M07) AS H07,
Sum(qCurrKoristajaTegevused.Tunnid*tblTegevus.M08) AS H08,
Sum(qCurrKoristajaTegevused.Tunnid*tblTegevus.M09) AS H09,
Sum(qCurrKoristajaTegevused.Tunnid*tblTegevus.M10) AS H10,
Sum(qCurrKoristajaTegevused.Tunnid*tblTegevus.M11) AS H11,
Sum(qCurrKoristajaTegevused.Tunnid*tblTegevus.M12) AS H12
FROM (tblKoristaja LEFT JOIN qCurrKoristajaTegevused ON tblKoristaja.TabN =
qCurrKoristajaTegevused.TabN) LEFT JOIN tblTegevus ON
qCurrKoristajaTegevused.TegevusID = tblTegevus.TegevusID
GROUP BY tblKoristaja.TabN;
,where qCurrKoristajaTegevused gives the list of actions on different
objects for every employee, and calculates reserved time fior every action
in hours:
SELECT tblPindTegevusKoristaja.TabN, qLastPindTegevusKoristaja.PindID,
qLastPindTegevusKoristaja.TegevusID,
[tblPindTegevus].[Tunnid]+[tblPindTegevus].[Minutid]/60 AS Tunnid
FROM (tblPindTegevusKoristaja RIGHT JOIN qLastPindTegevusKoristaja ON
(tblPindTegevusKoristaja.PindID = qLastPindTegevusKoristaja.PindID) AND
(tblPindTegevusKoristaja.TegevusID = qLastPindTegevusKoristaja.TegevusID))
LEFT JOIN tblPindTegevus ON (tblPindTegevusKoristaja.TegevusID =
tblPindTegevus.TegevusID) AND (tblPindTegevusKoristaja.PindID =
tblPindTegevus.PindID)
WHERE (((tblPindTegevusKoristaja.TabN) Is Not Null) AND
((tblPindTegevusKoristaja.Alates)=[qLastPindTegevusKoristaja].[Last]));
, where qLastPindTegevusKoristaja gives the last time for every action on
every object, some employee was attached to it, i.e. current people attached
with every action on every object:
SELECT tblPindTegevusKoristaja.PindID, tblPindTegevusKoristaja.TegevusID,
Max(tblPindTegevusKoristaja.Alates) AS [Last]
FROM tblPindTegevusKoristaja
GROUP BY tblPindTegevusKoristaja.PindID, tblPindTegevusKoristaja.TegevusID;
Of course I can process the table tblKoristaja row-by-row, and replace
estimated hours with ones read from query, but I was searching for a way to
do it with with one go. It looks like there is no easy way to do it. ?!?
Thanks anyway!
Arvi Laanemets
I suggest you post the SQL of "MyQuery" so that it can be determined if
you can use the query directly in an update query. If not, perhaps we can
suggest alternatives. You might tell us how many records (tens,
thousands, millions) are involved as that can affect the recommended
solution.
John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
.