Updating and inserting from table to table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hallo Everyone

I would like to copy all rows from one table to another who have an later Last_Edit date and who are new to the table. Here is what I have done

SNC_Table
Table1_ID Content Last_Edited GUID_ST
1 test 17/02/2004 06:59:34 1234
2 test2 17/02/2004 17:03:07 42352

SNC_Table
Table2_ID Content Last_Edited GUID_St
1 test 17/02/2004 06:59:34 123

UPDATE SNC_Table2 RIGHT JOIN SNC_Table1 O
([SNC_Table2].[GUID_Str]=[SNC_Table1].[GUID_Str]
AND ([SNC_Table2].[Last_Edited]<[SNC_Table1].[Last_Edited])
SET
SNC_Table2.Content = [SNC_Table1].[Content
, SNC_Table2.Last_Edited = [SNC_Table1].[Last_Edited
, SNC_Table2.GUID_Str = [SNC_Table1].[GUID_Str]

Give

Table2_ID Content Last_Edited GUID_St
1 test 17/02/2004 06:59:34 1234
9 test 17/02/2004 06:59:34 1234
10 test2 17/02/2004 17:03:07 42352

I would have like the result

Table2_ID Content Last_Edited GUID_St
1 test 17/02/2004 06:59:34 1234
9 test2 17/02/2004 17:03:07 42352

Can anyone see where I went wrong

Thanks..

Nigel..
 
Hi,



Try changing

AND ([SNC_Table2].[Last_Edited]<[SNC_Table1].[Last_Edited])


into

AND ([SNC_Table2].[Last_Edited] <= [SNC_Table1].[Last_Edited])



Hoping it may help,
Vanderghast, Access MVP



Nigel Findlater said:
Hallo Everyone,

I would like to copy all rows from one table to another who have an later
Last_Edit date and who are new to the table. Here is what I have done:
SNC_Table1
Table1_ID Content Last_Edited GUID_STR
1 test 17/02/2004 06:59:34 1234
2 test2 17/02/2004 17:03:07 42352

SNC_Table2
Table2_ID Content Last_Edited GUID_Str
1 test 17/02/2004 06:59:34 1234

UPDATE SNC_Table2 RIGHT JOIN SNC_Table1 ON
([SNC_Table2].[GUID_Str]=[SNC_Table1].[GUID_Str])
AND ([SNC_Table2].[Last_Edited]<[SNC_Table1].[Last_Edited])
SET
SNC_Table2.Content = [SNC_Table1].[Content]
, SNC_Table2.Last_Edited = [SNC_Table1].[Last_Edited]
, SNC_Table2.GUID_Str = [SNC_Table1].[GUID_Str];

Gives

Table2_ID Content Last_Edited GUID_Str
1 test 17/02/2004 06:59:34 1234
9 test 17/02/2004 06:59:34 1234
10 test2 17/02/2004 17:03:07 42352

I would have like the result

Table2_ID Content Last_Edited GUID_Str
1 test 17/02/2004 06:59:34 1234
9 test2 17/02/2004 17:03:07 42352

Can anyone see where I went wrong?

Thanks...

Nigel...
 
Back
Top