--1、数据表已经创建,Excel首行作为表头     

--启用Ad Hoc Distributed Queries:  

exec sp_configure 'show advanced options',1    

reconfigure    

exec sp_configure 'Ad Hoc Distributed Queries',1  

 reconfigure  

 

 go

  --开始查询数据  

  if object_id('temp_XXX') is not null   

drop table temp_XXX go    

 

SELECT * into temp_XXX FROM OpenDataSource('Microsoft.ACE.OLEDB.12.0','Data Source=C:\Users\Administrator\AppData\Local\Temp\1\2012.xls;User ID=;Password=;Extended properties=Excel 5.0')...sheet1$  

 

--使用完成后,关闭Ad Hoc Distributed Queries:  

exec sp_configure 'Ad Hoc Distributed Queries',0  

 reconfigure    

exec sp_configure 'show advanced options',0  

 reconfigure     

 

   select * from temp_XXX;

posted on 2014-11-07 11:34  绯儿  阅读(194)  评论(0编辑  收藏  举报