Pages

Saturday, June 1, 2013

How to import Excel data with OPENROWSET?

Execute the following Microsoft SQL Server Transact-SQL scripts to demonstrate the alternative ways of importing Excel worksheet data with OPENROWSET. 
SELECT *
INTO #SpreadSheet1
FROM
OPENROWSET('Microsoft.Jet.OLEDB.4.0'
,'Excel 8.0;Database=D:\data\excel\generalledger.xls'
,'SELECT * FROM [Sheet1$]'
)
GO

SELECT *
INTO #SpreadSheet2
FROM OPENROWSET('MSDASQL',
    'Driver={Microsoft Excel Driver (*.xls)};DBQ=D:\data\excel\generalledger.xls',
    'SELECT * FROM [Sheet1$]')
GO

SELECT * FROM #SpreadSheet1
GO

SELECT * FROM #SpreadSheet2
GO

No comments:

Post a Comment