2017-10-04 44 views
0

我想從兩個不同的查詢附加兩個不同的文件;這是我的代碼,這是造成這個問題的標題中提到的錯誤:從兩個不同的查詢郵件發送兩個不同的附件從SQL

EXEC msdb.dbo.sp_send_dbmail 
    @profile_name='MyTestMail 
    @body = @body, 
    @body_format ='HTML', 
    @recipients = '[email protected]', 
    @subject = @SBJ, 
    @importance = HIGH, 
    @sensitivity= Confidential, 
    @query = 'Select * from XXXXXXXX;', 
    @attach_query_result_as_file = 1, 
    @query_attachment_filename = 'X1.csv', 
    @query_result_separator=',', 
    @query_result_width =32767, 
    @query_result_no_padding=1, 
    @query = 'Select * from XXXXXXXX2;', 
    @attach_query_result_as_file = 1, 
    @query_attachment_filename = 'X2.csv', 
    @query_result_separator=',', 
    @query_result_width =32767, 
    @query_result_no_padding=1; 

我可以成功發送一個文件作爲附件從相同的代碼,如果不是XXXXXXXX2重複查詢。

+1

的[試圖找出如何發送與SP \ _send \ _dbmail多個文件附件]可能的複製(https://stackoverflow.com/questions/2518261/trying-to如何發送多文件附件與sp-send-dbmail) – MatSnow

+0

@Matsnow我很抱歉令你失望,但我在這裏尋找別的東西,我想發送兩個文件作爲單個電子郵件中兩個不同查詢的附件,而不保存在本地計算機上。 –

回答

0

只有從文件系統連接時才能附加多個文件。 請參考下面的語法 -

sp_send_dbmail [ [ @profile_name = ] 'profile_name' ] 
     [ , [ @recipients = ] 'recipients [ ; ...n ]' ] 
     [ , [ @copy_recipients = ] 'copy_recipient [ ; ...n ]' ] 
     [ , [ @blind_copy_recipients = ] 'blind_copy_recipient [ ; ...n ]' ] 
     [ , [ @from_address = ] 'from_address' ] 
     [ , [ @reply_to = ] 'reply_to' ] 
     [ , [ @subject = ] 'subject' ] 
     [ , [ @body = ] 'body' ] 
     [ , [ @body_format = ] 'body_format' ] 
     [ , [ @importance = ] 'importance' ] 
     [ , [ @sensitivity = ] 'sensitivity' ] 
     [ , [ @file_attachments = ] 'attachment [ ; ...n ]' ] 
     [ , [ @query = ] 'query' ] 
     [ , [ @execute_query_database = ] 'execute_query_database' ] 
     [ , [ @attach_query_result_as_file = ] attach_query_result_as_file ] 
     [ , [ @query_attachment_filename = ] query_attachment_filename ] 
     [ , [ @query_result_header = ] query_result_header ] 
     [ , [ @query_result_width = ] query_result_width ] 
     [ , [ @query_result_separator = ] 'query_result_separator' ] 
     [ , [ @exclude_query_output = ] exclude_query_output ] 
     [ , [ @append_query_error = ] append_query_error ] 
     [ , [ @query_no_truncate = ] query_no_truncate ] 
     [ , [ @query_result_no_padding = ] @query_result_no_padding ] 
     [ , [ @mailitem_id = ] mailitem_id ] [ OUTPUT ] 
相關問題