August 29, 2006 at 5:45 am
How can I import data from a CSV into an existing table but ignore duplicate records?
August 29, 2006 at 6:56 am
You usually create a staging table where you import the data. Then you insert the "valid" records with something like this :
Insert into dbo.RealTable (Key, Col1, Col2) Select Key, Col1, Col2 from dbo.Staging S where not exists (Select Key from dbo.RealTable RT where S.Key = RT.Key)
That will only insert data that is not already in the table based on a single column primary key.
August 29, 2006 at 9:43 am
Works like a charm. Thank you. Thank you. Wow there is so much to learn about SQL.
August 29, 2006 at 9:46 am
6000 + posts and now I have to start all over again with sql 2005
. Hopefully I have a headstart this time
.
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply