启用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
执行此句之前必须建好xls,并且在第一行设置列名
insert into OPENROWSET('MICROSOFT.JET.OLEDB.4.0' ,'Excel 5.0;HDR=YES;DATABASE=d:/test.xls',sheet1$) select * from dbo.DetectionInitialData
- --采用SQL语句实现sql2005和Excel 数据之间的数据导入导出,在网上找来一--下,实现方法是这样的:
- --Excel---->SQL2005 导入:
- select * into useinfo from OPENROWSET('MICROSOFT.JET.OLEDB.4.0' ,'Excel 5.0;HDR=YES;DATABASE=d:/db.xls',sheet1$);
- --其中,useinfo 是数据库中的一个表,d:/db.xls 为数据源,值得提出的是:--sheet1$,记得加上$。
- ---SQL2005--->Excel 导出:
- insert into OPENROWSET('MICROSOFT.JET.OLEDB.4.0' ,'Excel 5.0;HDR=YES;DATABASE=d:/test.xls',sheet1$) select * from useinfo;
- --新建一个test.xml 文件,其中test.xml的sheet1 的表头必须要和useinfo的列----名相一致.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ----附上access的
- insert into OpenRowSet('microsoft.jet.oledb.4.0',';database=d:/test.mdb','select * from useinfo')
- select * from useinfo;
- ----------------------------------------------------------------------------
- select * into hi from
- OpenRowSet('microsoft.jet.oledb.4.0',';database=d:/test.mdb','select * from useinfo')
- ``````````````````````````````````````````