Moving Excel spreadsheet data into SQL tables

Status
Not open for further replies.
Hello,

I have an excel spreadsheet that I have to put into SQL tables (MS SQL). Now the tables are already setup so I need to add this data into them. The spreadsheet is setup reflecting the tables (ie: it has the same column name as the equivalent sql table field name).

I have a few problems:

1) How do I get this data from the spreadsheet into the db (I have to also do checks to make sure this data does not already exist in the tables). Is there a way to import this data into a temporary table?

2) I need to put this data into 5 different tables, but all the data is included in 1 spreadsheet. For example, on the first row the first 34 columns of that row go into table 1, the next 5 columns go into table 2, etc.

I don't know if I should split up the data (ie: make 5 temp tables all holding only data for a specific table). The only way I could tell which data belongs to which users is bringing in the name fields into each of the 5 tables to match records. I guess i could bring whatever data I want in even overlapping fields to be able to tell which data belongs to which user, else I won't know.

Anyone know what the best way to do this is?

thanks
 

jbfraley

Seniorius Lurkius
30
Just use the Data Transformation Services wizard to read it directly from an excel spreadsheet and put it in a temporary table on the server. Make sure you rename your columns on the temporary table to get rid of annoying spaces or other funny characters from your Excel spreadsheet headings.

Then you'll need to write a cursor to read through the temporary table, transform as required, and insert into the destination table.

If you don't care about integrity, try to get the wizard to map it directly to the desired table.
 
Status
Not open for further replies.