Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import Excel spreadsheet columns into SQL Server database

I have an Excel spreadsheet that I want to import select columns into my SQL Server 2008 database table. The wizard didn't offer that option.

Do any easy code options exist?

like image 443
user47206 Avatar asked Dec 17 '08 20:12

user47206


People also ask

How do I import a column of Excel into another SQL Server?

Right-click the selected cells and select Copy. Switch back to SQL Server Management Studio and scroll down to the last row at the bottom and locate the row with a star in the left-most column. Right click the star in the column header and select Paste.

How do I automatically import data from Excel to SQL Server?

For on-premise solution: One time: could right click database instance and choose Task-> Import Data. Automatic: build SSIS package and schedule job in SQL server to run ETL process.


2 Answers

Once connected to Sql Server 2005 Database, From Object Explorer Window, right click on the database which you want to import table into. Select Tasks -> Import Data. This is a simple tool and allows you to 'map' the incoming data into appropriate table. You can save the scripts to run again when needed.

like image 152
Tejas Avatar answered Sep 21 '22 16:09

Tejas


Microsoft suggest several methods:

  • SQL Server Data Transformation Services (DTS)
  • Microsoft SQL Server 2005 Integration Services (SSIS)
  • SQL Server linked servers
  • SQL Server distributed queries
  • ActiveX Data Objects (ADO) and the Microsoft OLE DB Provider for SQL Server
  • ADO and the Microsoft OLE DB Provider for Jet 4.0

If the wizard (DTS) isn't working (and I think it should) you could try something like this http://www.devasp.net/net/articles/display/771.html which basically suggests doing something like

INSERT INTO [tblTemp] ([Column1], [Column2], [Column3], [Column4])  SELECT A.[Column1], A.[Column2], A.[Column3], A.[Column4] FROM OPENROWSET  ('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=D:\Excel.xls;HDR=YES', 'select * from [Sheet1$]') AS A; 
like image 23
Ian G Avatar answered Sep 23 '22 16:09

Ian G