SELECT T.CARTA, Sum(T.IMPORTO) AS SommaDiIMPORTO
FROM T INNER JOIN DB_CARTE ON T.CARTA = DB_CARTE.CARTA
GROUP BY T.CARTA
Now, i need to update the field IMPORTO in DB_CARTE with SommaDiIMPORTO, possible?
summ and update
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: summ and update
You can't use a Totals query in an update query. Does this work?
I have assumed that CARTA is a text field. If it is a number field, omit the single quotes '.
Code: Select all
UPDATE DB_CARTE SET IMPORTO = DSum("IMPORTO", "T", "CARTA='" & CARTA & "'")
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
Re: summ and update
HansV wrote:You can't use a Totals query in an update query. Does this work?
I have assumed that CARTA is a text field. If it is a number field, omit the single quotes '.Code: Select all
UPDATE DB_CARTE SET IMPORTO = DSum("IMPORTO", "T", "CARTA='" & CARTA & "'")
Sorry me Hans but you just have posted a solution for this prob.
In other case tks.
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
Re: summ and update
Hans, sorry me but...HansV wrote:You can't use a Totals query in an update query. Does this work?
I have assumed that CARTA is a text field. If it is a number field, omit the single quotes '.Code: Select all
UPDATE DB_CARTE SET IMPORTO = DSum("IMPORTO", "T", "CARTA='" & CARTA & "'")
Is possible to count how many occurence are compressed in DSum and put the count value into the correspondent field NrTot?
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: summ and update
Perhaps
Code: Select all
UPDATE DB_CARTE SET IMPORTO = DSum("IMPORTO", "T", "CARTA='" & CARTA & "'"), NrTot = DCount("IMPORTO", "T", "CARTA='" & CARTA & "'")
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
Re: summ and update
work perfect!HansV wrote:Perhaps
Code: Select all
UPDATE DB_CARTE SET IMPORTO = DSum("IMPORTO", "T", "CARTA='" & CARTA & "'"), NrTot = DCount("IMPORTO", "T", "CARTA='" & CARTA & "'")
tks
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
Re: summ and update
Based this sql is possible to summ the result to the current value in Importo and in nrtot with a where on db_carte field data1=12/11/2013?HansV wrote:Perhaps
Code: Select all
UPDATE DB_CARTE SET IMPORTO = DSum("IMPORTO", "T", "CARTA='" & CARTA & "'"), NrTot = DCount("IMPORTO", "T", "CARTA='" & CARTA & "'")
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
Re: summ and update
HansV wrote:You can add a WHERE clause to the SQL.
ok for tath.
but i need to summ the result of query to the current value in the fields NrTot and IMPORTO...
before to run query i have:
NrTot =2
IMPORTO=100
result of query
NrTot =1
IMPORTO=500
i need:
NrTot =3
IMPORTO=600
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: summ and update
OK, so you need to add the DSum result to the value of IMPORTO and of NrTot. So you use
... SET IMPORTO = IMPORTO + DSum(...), NrTot = NrTot + DSum(...) WHERE ...
... SET IMPORTO = IMPORTO + DSum(...), NrTot = NrTot + DSum(...) WHERE ...
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
Re: summ and update
HansV wrote:OK, so you need to add the DSum result to the value of IMPORTO and of NrTot. So you use
... SET IMPORTO = IMPORTO + DSum(...), NrTot = NrTot + DSum(...) WHERE ...
peraphs:
NrTot = NrTot + DCount
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands