Pages

Tuesday 26 February 2013

Insert Excel Data into a SQL Server table using OPENROWSET

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.
1SELECT * FROM #myExcelData
2GO

No comments:

Post a Comment