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!

SQL Import Script

Status
Not open for further replies.

Dodge

IS-IT--Management
Jun 14, 2001
25
0
0
US
I'm trying to import some data, simple enough right? Well maybe for some of you.

I exported some of the columns to Excel. They were updated and now need to be imported. The problem is that I can't/don't want any duplicates and can't delete and update because I only exported some of the columns. Bacially I need to tell it that if Column#1 Row#1 from the excel has a match in Column#1 on table, to change the data in that row in the apropriate column; If Column#1 Row#1 from the excel doesnt match then add it.

I hope all that makes sense to somebody. I'm new at SQL so any help at all would be great.

Thanks
Dodge
 

I suggest the following.[ol][li]Create a new table for importing the Excel spreadsheet.

[li]Import the spreadsheet into the new table.

[li]Create an Update query to update matching records in the existing table with data from the new table.

Update OldTable Set column2=n.column2, column3=n.column3, column4=n.column4, ...
From OldTable o Inner Join NewTable n
On o.column1=n.column1

[li]Create an Insert query that will insert data from the new table that has no match in the existing table.

Insert OldTable
Select * From NewTable
Where column1 Not In (Select Column1 From OldTable)

[li]When all updates are completed, delete the new table.[/ol] Terry Broadbent
Please review faq183-874.

"The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge." - Daniel J Boorstin
 
Thanks, Worked like a Champ
Dodge
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top