SQL send mail-HTML format

Source: Internet
Author: User

ALTER PROCEDURE dbo.sx_pro_autoemailcontent

As

Begin

DECLARE @Rqty int

DECLARE @n int

DECLARE @m_recipients varchar (1000)

DECLARE @m_copy_recipients varchar (1000)

DECLARE @m_Query varchar (1000)

DECLARE @m_Body varchar (1000)

DECLARE @m_subject varchar (50)

DECLARE @m_AttachAsFile int

DECLARE @m_FileName varchar (50)

DECLARE @m_Frequency varchar (10)

DECLARE @tableHTML NVARCHAR (MAX)

Set @Rqty = (select count (*) from Sx_bas_autoemail_list)

Set @n=1

While @n<[email protected]

Begin

Select

@m_recipients =recipients,

@m_copy_recipients =copy_recipients,

@m_Query =sqlstr,

@m_Body =body,

@m_subject =subject,

@m_AttachAsFile =attachasfile,

@m_FileName =file_name,

@m_Frequency =frequency from sx_bas_autoemail_list WHERE [email protected]

If @m_Frequency = ' Daily ' or (@m_Frequency = ' Monthly ' and Day (getdate ()) =1) or (@m_Frequency = ' Weekly ' and DatePart (DW, GETDATE ()) =1)

Begin

EXEC Msdb.dbo.sp_send_dbmail

@profile_name = ' Db_automail ',

@recipients = @m_recipients,

@copy_recipients [Email protected]_copy_recipients,

@[email Protected]_query,

@body = @m_Body,

@subject [Email Protected]_subject,

@execute_query_database = ' sxquadb ',

@attach_query_result_as_file [Email Protected]_attachasfile,

@[email Protected]_filename;

[Email Protected]_format = ' HTML ';

End

Set @[email protected]+1

End

[Email protected]_name = ' Saeg_db_automail ',

End

SQL send mail-HTML format

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.