1、将EXECEL导入到SQLSERVER2005数据库方法示例:
insert into dbo.tbpointconfig(pointname,punit,pmax,pmin,pvalue,generatorid,pdate,cdbh)
SELECT 测点名称,单位,PMAX,PMIN,PVALUE,机组号,PDATE,TAGNAME
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="d:\荆州热电模拟量点表.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...[Sheet2$]
2、SQLSERVER2005导出到EXECELF方法示例:
EXEC master..xp_cmdshell 'bcp 库名.dbo.表名out c:\Temp.xls -c -q -S"servername" -U"sa" -P""'
参数:S 是SQL服务器名;U是用户;P是密码
说明:还可以导出文本文件等多种格式
INSERT INTO
OPENDATASOURCE('Microsoft.JET.OLEDB.4.0',
'Extended Properties=Excel 8.0;Data source=C:\training\inventur.xls')...[Filiale1$]
(bestand, produkt) VALUES (20, 'Test')
insert into openrowset('Microsoft.Jet.OLEDB.4.0','EXCEL 8.0;HDR=YES;User id=admin;Password=;IMEX=1;
DATABASE=D:\Roy.xls', sheet1$)--(ID,Name)
select 2,'b'
insert into OPENROWSET('MICROSOFT.JET.OLEDB.4.0','Excel 8.0;HDR=YES;DATABASE=D:\Roy.xls',sheet1$)(ID,Name)
select 2,'b'