Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating an existing SQL table with values from an excel spreadsheet

Status
Not open for further replies.

DellHater

Programmer
Nov 24, 2006
75
CZ
Hi All

I'm using SQL 2008, I need to update some existing values in a table and am trying to find a way to do it.
I have exported the table using the wizard to an excel spreadsheet.

On other tables I updated the excel sheet, deleted the existing table in SQl and then re-imported the excel into a new table . all worked ok.

Problem I got now is that I can't delete the original table, or rename it due to dependencies.
So i need a way to update the values in the table (replace existing text) using SQL and get my new values from the excel sheet.

Anyone got a way to do this ?

cheers
 
Have you got a column in the data that uniquely identifies a row of data? If so, I would recommend that you import to a temporary holding table and then use it to update the real table. The query would look something like this:

Code:
Update YourRealTable
Set    YourRealTable.EyeColor = HoldingTable.EyeColor,
       YourRealTable.ShowSize = HoldingTable.ShowSize
From   YourRealTable
       Inner Join HoldingTable
         On YourRealTable.UniqueRowIdentifier = HoldingTable.UniqueRowIdentifier


-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
You might want to show a data example and what you want to accomplish. Also how many records are we talking about.

You might be able to create dynamic update statements in excel then just run a script to do the updates.

Simi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top