Updating one table with data from another table in SQL2000 -
02-16-2006
, 02:54 PM
Hi All:
I am a newbie at SQL, and I have a two-part question, that I am hoping you
can help me with. Please bear with me.
Original Issue:
We have a non-MS-SQL database that exports data into many text files on a
daily basis.
We then use DTS jobs to import(append) the text files into MS SQL2000 tables
that we use for reporting.
Problem is that every once in a while, the other db exports data into the
text files that matches existing primary keys in our SQL Tables. This causes
the DTS to fail because of a primary key violation and the data for that day
does not get added into our SQL table. This of course causes our reporting
to go haywire.
Attempted Solution:
Based on my research, I have come up with the following solution:
1) Create a TempTable in SQL
2) Import the data from the text file into the TempTable
3) Use an Update SQL task to update the data in PermTable with the data in
TempTable, without causing PK violation errors or duplicating entries. (In
case of Primary Keys matching, I do not care if it overwrites the existing
data in the PermTable or if it just keeps the existing data and moves on to
the next row)
4) Drop the TempTable in SQL.
I figured out how to do 1, 2 & 4 but I have not found any good examples for
an Update SQL statement that I could adapt.
My question is as follows:
A) Am I on the right track or is there an easier way to solve the original
issue.
B) If I am on the right track, then I would appreciate it if somebody could
write a sql UPDATE statement for me using the following variables if at all
possible.
TempTable PermTable
Column1 = ColumnA
Column2 = ColumnB
Column3 = ColumnC
Also, to satisfy my curiosity, does an Update statement overwrite data or
just ignore the existing row and move on to the next row? I would assume
overwrite
Help is very much appreciated.
StaarTech |