dbTalk Databases Forums  

Updating one table with data from another table in SQL2000

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Updating one table with data from another table in SQL2000 in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
StaarTech
 
Posts: n/a

Default 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

Reply With Quote
  #2  
Old   
David Portas
 
Posts: n/a

Default Re: Updating one table with data from another table in SQL2000 - 02-16-2006 , 03:25 PM






Answered in .programming

Please don't multi-post.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.