How do I import an Excel spreadsheet into SQL Server 2008R2 database?
There is a microsoft knowledge base article that lays out all the ways this is possible.
http://support.microsoft.com/kb/321686
I think using OPENROWSET or OPENDATASOURCE will be the easiest way, without the wizard. (see Distributed Queries)
SELECT * INTO XLImport4 FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\test\xltest.xls', [Customers$])
See OPENROWSET documentation, with examples lower down the page.
http://msdn.microsoft.com/en-us/library/ms190312.aspx
Manually
Right click on the database name/go to task and then select import data, as a source select an excel file that you created before and choose it's path on the next page select sql server as destination
Import Excel to SQL Server 2008
If you're limited solely to TSQL
, the above two answers will show you some ideas. If you have access to either Data Tools
or Business Intelligence
, with SSIS
, you can automate it with the assumption that each sheet in the Excel workbook matches each time. With SSIS
, you'll use a Data Flow task and each sheet will be imported into the table that you want. When you're ready for the file the next week, you'll drop it into the folder and run the SSIS
package.
However, if the sheet names change, (for instance, one week sheets are called Cats, Dogs, Rain and the next week it's Sulfur, Fire, Hell) then this would cause the package to break. Otherwise, if only the data within the worksheet change, then this can be completely automated with SSIS.
Example article: https://www.simple-talk.com/sql/ssis/moving-data-from-excel-to-sql-server---10-steps-to-follow/
how to import an excel file into sqlserver 2008
There is a microsoft knowledge base article that lays out all the ways this is possible.
http://support.microsoft.com/kb/321686
I think using OPENROWSET
or OPENDATASOURCE
will be the easiest way, without the wizard. (see Distributed Queries)
SELECT * INTO XLImport4 FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\test\xltest.xls', [Customers$])
See OPENROWSET documentation, with examples lower down the page.
http://msdn.microsoft.com/en-us/library/ms190312.aspx
Import multiple Excel files into SQL Server 2008 R2 using SSIS Packages?
since you have only 2 excel files and only two tables I don't see why use a foreach loop. Just follow this link and do it directly
If you need to insert from both excel files to both databases you can use a multicast component to create a copy of a dataset
Related Topics
Postgres Query of an Array Using Like
Why Doesn't Oracle Raise "Ora-00918: Column Ambiguously Defined" for This Query
Performance of String Comparison VS Int Join in SQL
Sql: Syntax Error with Intersect
SQL Server - Group Records by N Minutes Interval
How to Get This Timestamp in the Format I Want, Oracle SQL
Parameterized Query in Ms Access 2003 Using Vba
Parse a Date from Unformatted Text in SQL
SQL Server Query Xml Attribute for an Element Value
How to Perform the Same Aggregation on Every Column, Without Listing the Columns
Does Ms Access Suppress Primary Key Violations on Inserts
Concat Group by in Vertica SQL
Change Separator of Wm_Concat Function of Oracle 11Gr2
SQL Group and Sum by Month - Default to Zero
Cte in from Clause of SQL Query
Calculating SQL Server Row_Number() Over() for a Derived Table
SQL Server Performance for Alter Table Alter Column Change Data Type