用sql语句将查询结果导入到execl

解决方案概述:
     如果从SQL数据库中,导出数据到Excel, 首先如果Excel文件已经存在,而且已经按照要接收的数据创建好表头,就可以简单的用TSQL语句, 但使用前,必须把功能给打开
use master
go
sp_configure 'show advanced options',1
reconfigure
go
sp_configure 'Ad Hoc Distributed Queries', 1
go
reconfigure
go
然后, use 你的数据库,假设excel文件名为book1.xls, 表名为testexcel
insert into OPENROWSET('MICROSOFT.JET.OLEDB.4.0'
,'Excel 5.0;HDR=YES;DATABASE=c:\data\book1.xls',sheet1$)
select * from testexcel
posted @ 2008-09-04 08:58  玉玉  阅读(582)  评论(0编辑  收藏  举报