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
 General SQL Server Forums
 New to SQL Server Programming
 Importing data from another table

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2011-02-28 : 11:07:42
I'm working with two tables that are identical. A current table and history table.

Trying to import the current table and append to the history table.

The import fails because of a duplicate key. The key it is failing on is the records unique ID. If I look at the current tables ID for a record and query that ID in the history table the records are different.

Is there a way to have the DTS create a new ID for the record when it is imported?

mikgri
Starting Member

39 Posts

Posted - 2011-03-01 : 15:30:49
Yes you can write a query for insert, in DTS check "Write a query to specify the data to transfer" option and populate new id's.
It seems that you have duplicates in your tables, try this:
select a.* from table1 a inner join table2 b on a.id=b.id
to find out if there are duplicates in tables.

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-03-01 : 15:38:16
can you post the DDL of the tables?

And why would you want to create a new ID instead of doing an update for existing ID's and an INSERT for non existing (or doing a delete for ones that don't exists anymore for that matter)



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -