SQL Server sends HTML-formatted messages in the following reference code:
DECLARE @tableHTML NVARCHAR (MAX);
--Get the current system time, and data statistics time Set @d_nowdate = CONVERT (datetime,convert (varchar), DATEADD (Day,-1,getdate ()), 120, 120); --If there is data, send the IF exists (select top 1 * T_TABLE1 (NOLOCK) where d_rq= @d_nowdate) begin set @str_subject = ' So-and-so ' +
CONVERT (varchar), @d_nowdate, 120) + ' net worth. ' SET @tableHTML = n ' <H1> xxx </H1><br> current test <br><table border= "1" > ' + N ' <tr><th > Date </th><th> Fund code </th><th> Fund name </th><th> NET value </th><th> Cumulative net value </ Th></tr> ' + CAST (select CONVERT (varchar, @d_nowdate,) as ' TD ', ', VC_JJDM as ' TD ', ', VC_JJMC as ' t d ', ', 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> '; --Send mail exec @i_result = msdb.dbO.sp_send_dbmail @profile_name = ' Profile-mail ', @recipients = ' Email address 1; mailbox 2; Mailbox 3 ', @subject
= @str_subject, @body = @tableHTML, @body_format = ' HTML '; End
The message effects are as follows:
Certain net value
In the current test
Date |
Fund code |
Fund name |
Net worth |
Cumulative net Value |
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 |