Thursday, July 8, 2010

Import Excel File Into SQL Server

First we need to enable the use of "Ad Hoc Distributed Queries" by using "SP_CONFIGURE"

1.- Open SQL server & New Query
2.- Run the command sp_configure
















3.- If we can not see the option "Ad Hoc Distributed Queries", we need activate "show advanced options"
     with the command "sp_configure 'show advanced options', 1", and then the commando        "reconfigure".

4.- If you run again the command "sp_configure" you will see the "Ad Hoc Distributed Queries" 

 
5.- Now we need anable Ad Hoc Distributed Queries, with the follow command "sp_configure 'Ad Hoc Distributed Queries', 1 " and the "reconfigure"

6.- Finally we are going to execute the following Query.

SELECT * INTO table FROM  OPENROWSET ('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=D:\Book1.xls', 'SELECT * FROM [Sheet1$]')

Where:
table = New table name.
Database = Excel file path
Sheet1 = Name Sheet

1 comment:

  1. Este tuto esta mensional algunos detalles interesantes de exportacion xls http://geekswithblogs.net/nagendraprasad/archive/2009/03/26/export-sql-server-data-into-excel.aspx

    ReplyDelete