2017-11-20 4 views
0

SQL Server에서 SQLmail을 사용하여 전자 메일을 보내려고하지만 원하는 출력을 얻을 수 없습니다.SQL 서버에서 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';