SQL Journey

Journey of SQL Server & Microsoft Business Intelligence

Insert Excel Data into a SQL Server table using OPENROWSET

Posted by Prashant on June 16, 2010


There are many ways to load excel data into SQL Server database, using DTS, BULK import, SSIS and many others. In this post I will go with OPENROWSET. This is very useful when we need ad-hoc connection to an OLE DB source.

Here below is the image of the excel file taken for demonstrate.

Here is the script to import the file into SQL Server database using OPENROWSET.

SELECT  exl.*
INTO #myExcelData
FROM OPENROWSET ('Microsoft.Ace.OLEDB.12.0'
,'Excel 12.0; Database=C:\Import\ExcelDataImport.xlsx; HDR=YES'
,'SELECT * FROM [Sheet1$]') AS exl
GO

Now see the data imported into our table.

SELECT * FROM #myExcelData
GO

Here I have taken Excel 2007 as source and a SQL Server temp table as destination. Let me know if this is useful to you.

4 Responses to “Insert Excel Data into a SQL Server table using OPENROWSET”

  1. jssvardhan said

    if i have data as 12232234 & 2343432 in one column its showing as Null, how to over come this?

  2. jssvardhan said

    i traied with all special characters, but no luck, please suggest me the solution thanks in advance.

  3. Prashant said

    Hi Jssvardhan,

    Both the above scenarios working with me, do one thing just change the formatting of the columns with such data to TEXT in excel and try to import.

  4. […] Insert Excel Data into a SQL Server table using OPENROWSET … – Jun 16, 2010 · There are many ways to load excel data into SQL Server database, using DTS, BULK import, SSIS and many others. In this post I will go with OPENROWSET…. […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: