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 학습자의 빠른 성장을 도와주세요!