Solved

Excel Spreadsheet -> SQL Server

Posted on 2007-03-19
4
240 Views
Last Modified: 2012-06-27
I have an excel spreadsheet that I need to insert into two database tables.

Each row in the spreadsheet signals a new record, but there is a catch. Columns A to J need to go into one table, while columns K to O need to go into another table but there needs to be a link/key created between the two tables so there's a link.

Any ideas anyone?
0
Comment
Question by:PeterErhard
  • 2
4 Comments
 
LVL 28

Expert Comment

by:imran_fast
ID: 18747332
Do it using a staging table first move all the data into one stagetable inside sql server and then use sql commands to move it to repective two tables.
0
 
LVL 16

Expert Comment

by:rboyd56
ID: 18747825
In the Exce1 worksheet create a deined range from A to J and another one from K to 0.  The when you do the import you specify the range as the table name in the Excel worksheet.  

As far as the link goes..is there a common column in each of the ranges that you can link on. IN other words does each of the ranges have a column that has the same data as the other range. Without that I do not see how you can link the data and have it consistently correct.
0
 

Author Comment

by:PeterErhard
ID: 18747857
Thanks for your response. Re your first paragraph, how did I specify the range, when I go and query the spreadsheet?

Unfortnaltey, no there isn't a link between the two, they're just on the same row.
0
 
LVL 16

Accepted Solution

by:
rboyd56 earned 500 total points
ID: 18748018
In the worksheet in Excel, select the range A to J (all columns and rows that you want imported). The go to Insert - Define - Name. Type in the name that you want ot use and click OK.

Then to import the worksheet:

Create the tables with the proper column definitions as the range in Excel, except make the first column in the tables an identity range.
Use the Import Wizard to import the Excel worksheets. Use a select query and use select * from <defined range>.
Pick the table to import into click the ellipse (...) and check enable identity insert

Finish the wiard and run the package
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question