在sqlserver数据库中查询excel中的数据

打开高级配置,重新配置,打开分布式网络查询,重新配置
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure


select * from OpenRowSet('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;HDR=Yes;IMEX=1;Database=E:/demo.xls',
'select * from [Sheet1$]') 

关闭分布式网络查询,重新配置,关闭高级配置,重新配置
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure

说明:如果是excel2007或者更高的版本,需要把excel另存在低版本03版的。

同时可以利用这个sql语句,实现excel中数据插入sqlserver数据库中,

直接用excel中的数据创建数据表demo,并导入数据,不过此时,数据表的所有字段数据类型均为nvarchar(255)
select * into demo from OpenRowSet('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;HDR=Yes;IMEX=1;Database=E:/demo.xls',
'select * from [Sheet1$]') 

posted on 2013-06-21 14:44  流鼻涕的男孩  阅读(223)  评论(0)    收藏  举报

导航