最近因工作需要,需从第三方的excel表中读取数据与sqlserver2008中的表进行数据比对。因第一次操作,费了不少劲。
一.32位的系统对应安装32位的excel,64位操作系统对应安装64位的excel,不然office的access驱动安装后起不了作用,甚至会安装报错。
二.因为安全原因,需打开“show advanced options”和“Ad Hoc Distributed Queries”的外围应用配置器,
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
三.查询及引入语句,留意“[abcd$] ”表名要带“$”,
----查询
SELECT * FROM OpenDataSource
( 'Microsoft.ACE.OLEDB.12.0','Data Source=E:\test_one.xls;User ID=Admin;Password=;Extended properties=Excel 12.0')...[abcd$]
----插入
insert into FX_ZMD.dbo.product
SELECT * FROM OpenDataSource
( 'Microsoft.ACE.OLEDB.12.0','Data Source=E:\test_one.xls;User ID=Admin;Password=;Extended properties=Excel 12.0')...[abcd$]