SQL Server中发送HTML格式邮件的方法
2019/6/30 17:10:03
本文主要是介绍SQL Server中发送HTML格式邮件的方法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
sql server 发送html格式的邮件,参考代码如下:
DECLARE @tableHTML NVARCHAR(MAX) ; -- 获取当前系统时间,和数据统计的时间 set @d_nowdate = convert(datetime,convert(varchar(10),dateadd(day,-1,getdate()),120),120); -- 如果有数据则发送 if exists (select top 1 * from t_table1(nolock) where d_rq=@d_nowdate) begin set @str_subject='某某'+convert(varchar(10),@d_nowdate,120)+'净值.'; SET @tableHTML = N'<H1>某某</H1><br>目前测试中<br><table border="1">' + N'<tr><th>日期</th><th>基金代码</th><th>基金名称</th><th>净值</th><th>累计净值</th></tr>' + CAST ( (select convert(varchar(10),@d_nowdate,120) as 'td','',VC_JJDM as 'td','',Vc_jjmc as 'td','',EN_JJDWJZ as 'td','',EN_LJJZ as 'td' from t_table1 t left join t_table2 tt on t.VC_JJDM = tt.C_FUNDCODE where d_rq=@d_nowdate order by Vc_jjmc,VC_JJDM FOR XML PATH('tr'), ELEMENTS-- TYPE ) AS NVARCHAR(MAX) ) + N'</table>'; -- 发送邮件 exec @i_result = msdb.dbo.sp_send_dbmail @profile_name = 'Profile-Mail', @recipients = '邮箱地址1;邮箱2;邮箱3', @subject = @str_subject, @body = @tableHTML, @body_format = 'HTML'; end
邮件效果如下:
某某净值
目前测试中
日期 |
基金代码 |
基金名称 |
净值 |
累计净值 |
2013-12-20 |
111111 |
AAAAA |
0.98300000 |
0.98300000 |
2013-12-20 |
222222 |
BBBBB |
1.04900000 |
1.04900000 |
2013-12-20 |
333333 |
CCCCC |
0.64000000 |
0.64000000 |
2013-12-20 |
444444 |
DDDDD |
0.99400000 |
0.99400000 |
2013-12-20 |
555555 |
EEEEE |
1.05700000 |
1.05700000 |
2013-12-20 |
666666 |
FFFFF |
0.73400000 |
0.73400000 |
这篇关于SQL Server中发送HTML格式邮件的方法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-01-08Docker下的SqlServer发布订阅启用
- 2023-06-05Docker安装MS SQL Server并使用Navicat远程连接
- 2023-05-25深入浅出 SQL Server CDC 数据同步
- 2023-05-12通过空间占用和执行计划了解SQL Server的行存储索引
- 2023-04-24以SQLserver为例的Dapper详细讲解
- 2022-11-30SQL server高级函数查询
- 2022-11-26SQL SERVER数据库服务器CPU不能全部利用原因分析
- 2022-11-21SQL Server 时间算差值/常用函数
- 2022-11-20调试Archery连接SQL Server提示驱动错误
- 2022-10-22SQL Server 完整、差异备份+完整、差异还原(详细讲解,规避错误)