Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Update Table with Records from another table

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-11-11 : 10:33:33
cablerat writes "I have two tables, "Archive" and "Daily".

The Daily table has tickets that were closed out or updated yesterday in it.

The archive table has each day's daily table data appended to it it everyday.
They both have the exact same columns.
My question is this:
I have tried to find a way to update the "Archive Table" with all the records that are in the daily table but, not in the archive table. At the same time, I need to update the records that are in the archive table with any new updates that have been made(Some of the records in the daily table will already be in the archive table).

Archive Table = WFA_Closed_Trouble_Archive
Daily Table = CLDLUPD

I am currently doing:

DELETE a
FROM WFA_Closed_Trouble_Archive a
Left join CLDLUPD a2 ON (a.REPORT# = a2.REPORT#)
WHERE
a2.REPORT# IS Not NULL

This gets rid of all the records in the archive that are also in the daily.

Then:
I append the whole daily table to the archive table.

Is there a better way to do this?"

mr_mist
Grunnio

1870 Posts

Posted - 2002-11-11 : 10:36:15
quote:

cablerat writes "I have two tables, "Archive" and "Daily".

The Daily table has tickets that were closed out or updated yesterday in it.

The archive table has each day's daily table data appended to it it everyday.
They both have the exact same columns.
My question is this:
I have tried to find a way to update the "Archive Table" with all the records that are in the daily table but, not in the archive table. At the same time, I need to update the records that are in the archive table with any new updates that have been made(Some of the records in the daily table will already be in the archive table).

Archive Table = WFA_Closed_Trouble_Archive
Daily Table = CLDLUPD

I am currently doing:

DELETE a
FROM WFA_Closed_Trouble_Archive a
Left join CLDLUPD a2 ON (a.REPORT# = a2.REPORT#)
WHERE
a2.REPORT# IS Not NULL

This gets rid of all the records in the archive that are also in the daily.

Then:
I append the whole daily table to the archive table.

Is there a better way to do this?"



I normally do that the other way around. I INSERT all the records from daily into the archive that are not already there. Then I do an update that joins onto daily with join conditions for all the fields that might change.

Go to Top of Page
   

- Advertisement -