2017-11-20 22 views
0

SQL ServerからSQLmailを使用して電子メールを送信しようとしていますが、私が望む出力が得られません。SQL ServerからHTMLテーブルとして電子メールを送信

こんにちは:

次のプログラムはあなたのレビューのためにGETDATE()で@usernameによって提出されました - :

電子メールの本文:以下は私が何をしたいの例があります。 プログラムを確認して、さらに措置を講じてください。

want data as this tabular form in email body

よろしく、

@username



答えて

0

あなたの質問に答えるためにしようとする前に、私はいずれかを掲示するように、あなたの質問をより明確にするためにあなたを依頼したいですこのために書かれたスクリプトや、直面しているエラーなど、あなたのために簡単に質問を書くことができます。

以下は、要件を満たすのに役立つSQLスクリプトです。スクリプトは動作確認済みです。

declare @EmailBody NVARCHAR(MAX); 

declare @username VARCHAR(50) = 'Sean'; 

SET @EmailBody = N'<p style="font-family:arial; font-size:13px;">'+ 
           'Hello:<br/><br/>'+ 
           'Following program has been submitted by '+ @username +' at '+convert(varchar(50),getdate(),103)+ ' for your review.'+ 
           'Please review the program and take further action.<br/></p>'+ 
           '<table border="1" cellspacing="0" cellpadding="4" style="font-family: Arial; font-size: 11px;">' + 
           '<tr> 
            <td>Program No:</td> 
            <td>xxxxxxxxxxx</td> 
           </tr> 

           <tr> 
            <td>Description:</td> 
            <td>xxxxxxxxxxx</td> 
           </tr> 

           <tr> 
            <td>BUnit:</td> 
            <td>xxxxxxxxxxx</td> 
           </tr> 

           <tr> 
            <td>Program Type:</td> 
            <td>xxxxxxxxxxx</td> 
           </tr> 

           <tr> 
            <td>Product Line:</td> 
            <td>xxxxxxxxxxx</td> 
           </tr>'; 

--select @EmailBody 

EXEC msdb.dbo.SP_SEND_DBMAIL 
         @recipients='add recepients here seperated by ; eg : [email protected];[email protected]', 
         @subject = 'Write email subject here', 
         @body = @EmailBody, 
         @body_format = 'HTML';  
関連する問題