Habe table1 and table2
in table1 have dt data_esc agg fields
in table2 have rdt rdata_esc agg fields
i need with a vb code or a query tu update agg into table2 with agg from table1 based the match of dt&data_esec and rdt&rdata_esc
how to?
Hans is for you?
update column from two table
-
- Administrator
- Posts: 78512
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: update column from two table
This will probably only work if there is a unique index on the combination of dt and data_esc.
The SQL would be:
UPDATE table2 INNER JOIN table1 ON table2.rdt = table1.dt AND table2.rdata_esc = table1.data_esc SET table2.agg = table1.agg
The SQL would be:
UPDATE table2 INNER JOIN table1 ON table2.rdt = table1.dt AND table2.rdata_esc = table1.data_esc SET table2.agg = table1.agg
Last edited by HansV on 19 Oct 2010, 21:37, edited 1 time in total.
Reason: to correct error
Reason: to correct error
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4357
- Joined: 26 Apr 2010, 17:36
Re: update column from two table
error in bold value....HansV wrote:This will probably only work if there is a unique index on the combination of dt and data_esc.
The SQL would be:
UPDATE table2 INNER UNION table1 ON table2.rdt = table1.dt AND table2.rdata_esc = table1.data_esc SET table2.agg = table1.agg
Note:
rdt and dt are text format data_esc and rdat_esc are date format, peraphs is this the prob?
-
- Administrator
- Posts: 78512
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: update column from two table
Sorry, I posted "air code". It should have been
UPDATE table2 INNER JOIN table1 ON table2.rdt = table1.dt AND table2.rdata_esc = table1.data_esc SET table2.agg = table1.agg
UPDATE table2 INNER JOIN table1 ON table2.rdt = table1.dt AND table2.rdata_esc = table1.data_esc SET table2.agg = table1.agg
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4357
- Joined: 26 Apr 2010, 17:36
Re: update column from two table
no prob... for "air code"... i know, u are "artist ispired" now the code work perfect!HansV wrote:Sorry, I posted "air code". It should have been
UPDATE table2 INNER JOIN table1 ON table2.rdt = table1.dt AND table2.rdata_esc = table1.data_esc SET table2.agg = table1.agg
Note:
during the query i recived error refered the two different format on date_esec and rdata_esc i have used the same format (date) in all two fields and code query run good without error!