栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 数据库 > MySQL > MsSql

SQL Server中发送HTML格式邮件的方法

MsSql 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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'某某
目前测试中
' + N'' + 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'
日期基金代码基金名称净值累计净值
'; -- 发送邮件 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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/169475.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号