2017-11-27 1 views
0

Ich habe Body Text nach der Abfrage hinzufügen müssen, wenn Sie sp-send-dbmail verwenden. Momentan sieht meine gespeicherte Prozedur zum Senden von Mail so aus.Text nach Abfrage mit sp-send-dbmail

ALTER PROCEDURE [dbo].[sp_SendSFRProcesingEmail] 
    -- Add the parameters for the stored procedure here 
    (@cmp_code nvarchar(5), @email nvarchar(50), @rbc_email nvarchar(50)) 
AS 
BEGIN 
    -- SET NOCOUNT ON added to prevent extra result sets from 
    -- interfering with SELECT statements. 
    SET NOCOUNT ON; 

    -- Insert statements for procedure here 

DECLARE @profile nvarchar(50) 
DECLARE @subject nvarchar(100) 
DECLARE @querystr nvarchar (MAX) 

set @profile = 'Reports' 
set @subject = 'Company Service Fee Processing for ' + @cmp_code 
set @querystr = 'SET NOCOUNT ON 
SELECT [Year], [Week], [Description], [Cash_In**], [Cash_Out**], [Amt.Due] 
    FROM [001].[dbo].[SFR_Processing_LatestBatch] 
    WHERE [cmp_code] = '''[email protected]_code+''''; 


EXEC msdb.dbo.sp_send_dbmail 
@profile_name = @profile, 
@recipients = '[email protected]', 
@subject = @subject, 
@body = 'Note: This is an automatic e-mail message generated by Company. 

The Service Fee Information below was imported via an automated process from RGS. Please compare the information below to your records for the week listed and report any discrepancies immediately. 

If you have any questions or concerns regarding this email please contact your Regional Business Consultant. 

Thank you! 
Company, Inc. 
Accounting Department 
[email protected] 

**Amount(s) should equal Item 1 per weekly Service Fee Report for Account Number indicated in Subject Line. 

', 
@query = @querystr 

END 

Gibt es eine Möglichkeit die Abfrageergebnisse in der Mitte des Körpers irgendwo zu bewegen, anstatt am Ende der E-Mail wie in meinem Beispiel pic gezeigt?

enter image description here

+0

versuchen Sie den Körper mit 'HTML table'language und' CSS' wenn nötig – LONG

Antwort

1

Sie können einfach den Text als eine zweite Abfrage hinzuzufügen. Es wird die Zeile der Bindestriche oben generieren, aber da Sie NOCOUNT haben, sollte es sonst gut aussehen.

set @querystr = 'SET NOCOUNT ON 
SELECT [Year], [Week], [Description], [Cash_In**], [Cash_Out**], [Amt.Due] 
    FROM [001].[dbo].[SFR_Processing_LatestBatch] 
    WHERE [cmp_code] = '''[email protected]_code+'''; 
select ''Thank you! 

Company, Inc. 
Accounting Department 
[email protected] 

**etc.''';