SELECT *
FROM OpenDataSource( 'Microsoft.ACE.OLEDB.12.0',
'Data Source="c:\book1.xlsx";User ID=Admin;Password=;Extended properties=Excel 12.0')...[Sheet1$]
SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=C:\book1.xlsx', 'SELECT * FROM [Sheet1$A1:D100]')
SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=C:\book1.xlsx', 'SELECT * FROM [Sheet1$]')
SELECT *
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\book1.xls";User ID=Admin;Password=;Extended properties=Excel 8.0')...[Sheet1$]
SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=C:\book1.xls', 'SELECT * FROM [Sheet1$]')
SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=C:\book1.xls', 'SELECT * FROM [Sheet1$A1:D100]')
而且,还需要用拥有服务器sysadmin角色权限的登录帐号,先执行下列语句打开SQL SERVER的'Ad Hoc Distributed Queries'开关。
exec sp_configure 'show advanced options',1;reconfigure;
exec sp_configure 'Ad Hoc Distributed Queries',1;reconfigure;
exec sp_configure 'Ad Hoc Distributed Queries',0;
reconfigure;exec sp_configure 'show advanced options',0;reconfigure;