Thursday 21 June 2012

Query Excel data from Sql server


1. Download drivers and install in Sql server
http://download.microsoft.com/download/2/4/3/24375141-E08D-4803-AB0E-10F2E3A07AAA/AccessDatabaseEngine_x64.exe

2.
select * from
OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=D:\temp\temp.xlsx;',
'SELECT * FROM [Sheet1$]')
3. if user is not sysadmin, locate the provider in following registry path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Providers\

and add 
Value name: DisallowAdHocAccess
   Data type:  REG_DWORD
   Radix:      Hex
   Value: 0


No comments:

Post a Comment