Skip to content

Instantly share code, notes, and snippets.

@kujotx
Forked from anonymous/OPENROWSET to import SQL
Created June 12, 2013 21:05
Show Gist options
  • Save kujotx/5769103 to your computer and use it in GitHub Desktop.
Save kujotx/5769103 to your computer and use it in GitHub Desktop.
/*
First, you must configure ad hoc distributed queries, and configure the Access engineto work in SQL Server
*/
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO
exec sp_configure 'Advanced', 1;
GO
RECONFIGURE;
GO
exec sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1
RECONFIGURE;
GO
SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0 Xml;HDR=Yes;Database=C:\the\path\to\myfile.xlsx;', 'SELECT * FROM [Sheet1$]') -- also works with spaces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment