How to send HTML-formatted messages in SQL Server _mssql

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.