sp_send_dbmail:如果选择了特定变量,则发送电子邮件

时间:2017-08-18 11:34:04

标签: sql email stored-procedures

我目前在SQL中遇到一个问题,我有一个网站,如果选择了特定的类别,应该触发电子邮件。目前无论选择何种类别,它都会触发。

 IF @NotesCategory = 14

     EXEC msdb.dbo.sp_send_dbmail

     @profile_name = 'profilename',
     @from_address = @NotesSenderEmail,
     @reply_to     = @NotesSenderEmail,
     @recipients   = @Email,
     @subject      = 'subject',
     @body         = @mybody,
     @body_format  = 'HTML',
     @importance   = 'High'

END

......由于某种原因,如果Notes类别为14,它将会引发问候。

任何建议表示赞赏。非常感谢。

1 个答案:

答案 0 :(得分:1)

您错过了BEGIN

IF @NotesCategory = 14
    BEGIN
         EXEC msdb.dbo.sp_send_dbmail

         @profile_name = 'profilename',
         @from_address = @NotesSenderEmail,
         @reply_to     = @NotesSenderEmail,
         @recipients   = @Email,
         @subject      = 'subject',
         @body         = @mybody,
         @body_format  = 'HTML',
         @importance   = 'High'

    END