Home > Database > Mysql Tutorial > body text

SQLServer2008导出EXCEL文件,然后使用SQL脚本发送邮件的实现

WBOY
Release: 2016-06-07 15:07:21
Original
1739 people have browsed it

一.将表数据 导出 到EXCEL。 二.配置SQL SERVER2008 的Database Mail。 三.执行 邮件 发送 脚本 。 一.将表数据 导出 到EXCEL。 1,如果xp_cmdshell没有开启,开启xp_cmdshell的方法 -- To allow advanced options to be changed. EXEC sp_configure 'show a


一.将表数据导出到EXCEL。
二.配置SQL SERVER2008 的>Database Mail。
三.执行邮件发送脚本


一.将表数据导出到EXCEL。

1,如果xp_cmdshell没有开启,开启xp_cmdshell的方法
-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO

2,执行导出脚本
EXEC master..xp_cmdshell 'bcp "SELECT * FROM testDB.dbo.Table_1 " queryout C:/TEMP/test.xls -c -Utest -P123' --Sservername


二.配置SQL SERVER2008 的>Database Mail。
1.Management-->Database Mail(Right Click)-->Configure Database Mail(这里需要使用默认的SMTP服务器)
2.After send test mail success.
帮助可参考:ms-help://MS.SQLCC.v10/MS.SQLSVR.v10.en/s10de_6tsql/html/3bdb0e6d-9d09-465e-9a3f-7a8ccd53aca8.htm

三.执行邮件发送脚本

USE msdb
GO
EXEC sp_send_dbmail @profile_name='SQLMailProfileName',
@recipients='wqiu@test.com', @subject='Test message',
@body='This is the body of the test message. _
Congrats Database Mail Received By you Successfully.'
,@file_attachments = 'C:/TEMP/test.xls'
帮助可参考:ms-help://MS.SQLCC.v10/MS.SQLSVR.v10.en/s10de_6tsql/html/f1d7a795-a3fd-4043-ac4b-c781e76dab47.htm

 

对数据库邮件进行故障排除:

http://msdn.microsoft.com/zh-cn/library/ms188663.aspx

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template