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

WBOY
發布: 2016-06-07 15:07:21
原創
1709 人瀏覽過

一.将表数据 导出 到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

 

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!