阎娜三围,环球卡盘,泰国bee
--配置权限
exec sp_configure 'show advanced options', 1;
go
reconfigure;
go
exec sp_configure 'ad hoc distributed queries', 1;
go
reconfigure;
go
sql server 和excel的数据导入导出
1、在sql server里查询excel数据:
-- ======================================================
select *
from opendatasource( 'microsoft.jet.oledb.4.0',
'data source="c:\book1.xls";user id=admin;password=;extended properties=excel 5.0')...[sheet1$]
下面是个查询的示例,它通过用于 jet 的 ole db 提供程序查询 excel 电子表格。
select *
from opendatasource ( 'microsoft.jet.oledb.4.0',
'data source="c:\finance\account.xls";user id=admin;password=;extended properties=excel 5.0')...xactions
-------------------------------------------------------------------------------------------------
2、将excel的数据导入sql server :
-- ======================================================
select * into newtable
from opendatasource( 'microsoft.jet.oledb.4.0',
'data source="c:\book1.xls";user id=admin;password=;extended properties=excel 5.0')...[sheet1$]
实例:
select * into newtable
from opendatasource( 'microsoft.jet.oledb.4.0',
'data source="c:\finance\account.xls";user id=admin;password=;extended properties=excel 5.0')...xactions
-------------------------------------------------------------------------------------------------
3、将sql server中查询到的数据导成一个excel文件 -- ======================================================
t-sql代码:
exec master..xp_cmdshell 'bcp 库名.dbo.表名out c:\temp.xls -c -q -s"servername" -u"sa" -p""'
参数:s 是sql服务器名;u是用户;p是密码
说明:还可以导出文本文件等多种格式
实例:
exec master..xp_cmdshell 'bcp saletesttmp.dbo.cusaccount out c:\temp1.xls -c -q -s"pmserver" -u"sa" -p"sa"'
exec master..xp_cmdshell 'bcp "select au_fname, au_lname from pubs..authors order by au_lname" queryout c:\ authors.xls -c -sservername -usa -ppassword'
在vb6中应用ado导出excel文件代码:
dim cn as new adodb.connection
cn.open "driver={sql server};server=websvr;database=webmis;uid=sa;wd=123;"
cn.execute "master..xp_cmdshell 'bcp "select col1, col2 from 库名.dbo.表名" queryout e:\dt.xls -c -sservername -usa -ppassword'"
------------------------------------------------------------------------------------------------
4、在sql server里往excel插入数据:
-- ======================================================
insert into opendatasource( 'microsoft.jet.oledb.4.0',
'data source="c:\temp.xls";user id=admin;password=;extended properties=excel 5.0')...table1 (a1,a2,a3) values (1,2,3)
t-sql代码:
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')
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
-
sql某个日期是当年的第几周
/* *周一作为一周的开始 *当年的1月1号所在的周算作第一周 */ CREATE function GetWeekIndexFirstDate ( @...
[阅读全文]
-
-
数据库SQL---范式
1、数据冗余导致的问题:冗余存储、更新异常、插入异常、删除异常。 2、函数依赖:一种完整性约束。 在关系模式r(R)中,α属于R,β属于R。 1)α函数...
[阅读全文]
-
-
数据库SQL---查询
1、查询所有列 select *from emp;--*表示所有的,from emp表示从emp表中查询。 2、查询指定列 select empno,e...
[阅读全文]
-
-
-
-
网友评论