import missing field from excel into a mssql 2008R2 database

Hi guys. I’m struggeling with an import from an excel file into an existing mssql 2008R2 database table. We’re missing a field in this specific table. The excel file contains a column with  the value of this missing field and one with a key.

ID:  Missing field:
01      test1
02      test2
03      test3
My question how can I update the missing field from my excel file for each row?
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.

How are you trying to update the table.

1. Does the table have a column for the missing field?
2. Does the table have an "ID" which corresponds with the Excel file "ID"?
3. Are you using Excel to put into SQL, or SQL to pull from Excel
4. What version of Excel
5. Are you using SSIS or openrowset, or what method?
It depends how you are reading the excel file.
Need more info to answer this.
If the Excel file has ID as shown on your example that acts as primary key and the sql server table has one as well, then my proposal might work for you.

Here is my approach.

First, dump all the contents of the excel file into a staging table.

Then compare the data on the staging table with data on the actual table based on ID from both.

Then append to the actual table any data that is on the staging table but not on the actual table.

Works for me all the time.

If you have any questions, please ask.

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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

ValentinoVBI ConsultantCommented:
If you need info on how to get the Excel data into a table in your database, check out the following article:
Marten RuneSQL Expert/Infrastructure ArchitectCommented:
A simpler aproach than SSIS is to attach the excel by using a linked server.

Regards Marten
ValentinoVBI ConsultantCommented:
In addition to martenrune: which can be created on the fly using the OPENROWSET function :)

But it's not always straightforward as the following article will point out:
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

From novice to tech pro — start learning today.