Flat file to Insert Update

Hi I have a flat file of 400,000 records.

I have an existing table that matches the flat file. This wil be the second time I read the data in. The first time the table was empty. This time the table is full and about 10% of the fields will be new, 10% will need to be update. How can I read through the flat file and decide if the key already exists. If it does I want to update the table if it does not I want to insert the data into the table.  I do not know ahead of time which frows will have changes data so if I need to do every record that exists and update it thats ok.

This is a once every quarter update speed is not an issue.
Charles BaldoSoftware DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase AdministratorCommented:
You can probably copy the data into a temptable first, then you can update the values which are there in the master table and insert the new values from the temptable using an 'EXISTS' clause

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I agree: load the flat file into a "staging" table, and from there (after creating eventual indexes), update the production table.
if you need help on how to formulate the update/insert queries accordingly, or how to load the file into a table (BULK INSERT), ask.
Charles BaldoSoftware DeveloperAuthor Commented:

I understand its difficult to know exactly what the issue is and whats in a programmers mind. But ocassional it happens. Below is a link of almost exactly my issue and it was solved. The steps suggested by the experts were used. Thank both I will split the points.

Charles BaldoSoftware DeveloperAuthor Commented:
Thank You all I did give an excellent grade because I appreciate the quick response. However the solution was only a partial.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.