SQL SERVER与ACCESS、EXCEL导入导出

本人总结的SQLSERVER与ACCESS、EXCEL导入导出的相关操作

使用存储过程把SQLSERVER数据导入到excel

sp_configure 'xp_cmdshell', 1;

reconfigure;

 

EXEC master..xp_cmdshell 'bcp hm.dbo.meter out c:\Temp.xls -c -q -S"." -U"sa" -P"www"'

注意:

sa是用户名

www是密码

hm.dbo.meter是数据库表

C:\Temp.xls 是导出的文件

在SQL SERVER中查询excel数据

Excel数据如下,meter.xls,表为sheet2

 

 

 

exec sp_configure 'show advanced options',1

reconfigure

exec sp_configure 'Ad Hoc Distributed Queries',1

reconfigure

SELECT * FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0','Data Source="C:\meter.xls";User ID=Admin;Password=;Extended properties=Excel 8.0')...[sheet2$]

 

执行结果:

 

 

excel数据插入到SQL SERVER

 

exec sp_configure 'show advanced options',1

reconfigure

exec sp_configure 'Ad Hoc Distributed Queries',1

reconfigure

 

SELECT * into haha FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0','Data Source="C:\meter.xls";User ID=Admin;Password=;Extended properties=Excel 8.0')...[sheet2$]

 

 

SQL SERVER数据导入到excel

exec sp_configure 'show advanced options',1

reconfigure

exec sp_configure 'Ad Hoc Distributed Queries',1

reconfigure

insert into OpenDataSource( 'Microsoft.Jet.OLEDB.4.0','Data Source="C:\meter.xls";User ID=Admin;Password=;Extended properties=Excel 8.0')...[sheet3$] select RTU_Name from RTU

说明:此功能是将SQLSERVER中的RTU表数据的RTU_Name列数据导入到C:\meter.xls的sheet3中。

SQL SERVER数据导入到ACCESS

一.插入insert into

注意:C:\db1.mdb必须存在。表名:b 。字段名:Rtu_Name

insert into OpenDataSource( 'Microsoft.Jet.OLEDB.4.0','Data Source="C:\db1.mdb";User ID=Admin;Password=;')...[b] select RTU_Name from RTU

posted @ 2011-03-30 12:02  翱翔软件  阅读(276)  评论(0)    收藏  举报

欢迎访问翱翔软件