SIGN UP MEMBER LOGIN:    
ARTICLE

Import Data from SQL Server 2005 to Excel Sheet and Viceversa

Posted by Srinivas Articles | SQL Server 2012 May 11, 2009
This Article Shows How to Use SQL Server to Export Data from SQL Server to Excel Sheets and Viceversa.
Reader Level:


Import and Export data from SQL Server 2005 to XL Sheet:

In this article, I will explain how to upload the data from an Excel Sheet to a SQL Server 2005 database and also export data from a SQL Server database to an Excel sheet.

For uploading the data from Excel Sheet to SQL Server and viceversa, we need to create a linked server in SQL Server.

Procedure for creating a linked server in SQL Server 2005.

Expample linked server creation:

Before you executing the below command the excel sheet should be created in the specified path and it should contain the name of the columns.
 
EXEC sp_addlinkedserver 'ExcelSource2',
   'Jet 4.0',
   'Microsoft.Jet.OLEDB.4.0',
   'C:\Srinivas\Vdirectory\Testing\Marks.xls',
   NULL,
   'Excel 5.0'

Once you executed above query it will crate linked server in SQL Server 2005.

The following are the Query from sending the data from Excel sheet to SQL Server 2005.

INSERT INTO emp SELECT * from OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\text.xls','SELECT * FROM [sheet1$]')

The following query is for sending the data from SQL Server 2005 to Excel Sheet.

insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=c:\text.xls;',
'SELECT * FROM [sheet1$]') select * from emp

These two queries are working fine.

Login to add your contents and source code to this article
share this article :
post comment
 

Before run this query please create the linked server

Please try this query.

INSERT INTO Sampel SELECT * from OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\Upload Data into Sage\Upload.xls','SELECT * FROM [sheet1$]')

This is working on my machine.

I am not able to copy your query to SQL Server 2005.

The xls sheet should be abailiable in the given path and column name should match with the database column names.

Please check this one and revert back.

Posted by Srinivas Jun 11, 2010

Hi i am trying to import data from excel to sqlserver
 but i am getting error
can u plz solve me

my code is
INSERT INTO empdata SELECT * from OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\text.xls','SELECT * FROM [sheet2$]')

Posted by tharuni chini Jun 10, 2010

very useful
thanks very much

Posted by Su Tran May 20, 2010
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor