数据库
首页 > 数据库> > sql server 连接 EXCEL 直接查询

sql server 连接 EXCEL 直接查询

作者:互联网

1  SQL SERVER 中 查看有无访问接口,以下其中任何一个即可. 没有则下载  Microsoft Access Database Engine 2016 Redistributable (Microsoft Access 2016 数据库引擎可再发行程序包)  安装

 

 

 

2  开启 Ad Hoc Distributed Queries

启用Ad Hoc Distributed Queries:
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
   

关闭Ad Hoc Distributed Queries:
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure

  

3 设置 访问接口 属性

 

 

 

4 查询,注意 sheet名称后加上$符号.

--> ACE 引擎访问 Excel 2007  
select * from OpenRowSet('Microsoft.ACE.OLEDB.16.0', 'Excel 12.0;HDR=Yes;IMEX=1;Database=D:/2007.xlsx', 'select * from [Sheet1$]')  
select * from OpenRowSet('Microsoft.ACE.OLEDB.16.0', 'Excel 12.0;HDR=Yes;IMEX=1;Database=D:/2007.xlsx', [Sheet1$])  
select * from OpenDataSource('Microsoft.ACE.OLEDB.16.0', 'Excel 12.0;HDR=Yes;IMEX=1;Database=D:/2007.xlsx')...[Sheet1$]  
select * from OpenDataSource('Microsoft.ACE.OLEDB.16.0', 'Data Source=D:/2007.xlsx;Extended Properties="Excel 12.0;HDR=Yes;IMEX=1"')...[Sheet1$]

 

 

 

标签:Hoc,ACE,Distributed,Queries,EXCEL,server,sql,Microsoft,select
来源: https://www.cnblogs.com/BinBinGo/p/15471384.html