0

像这样使用时sp_send_dbmail

EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'MY_PROFILE'
    ,@recipients = 'MY_EMAIL_ADDRESS'
    ,@query = 'SELECT TOP 50 FIELD1, FIELD2, FIELD3 FROM TABLE1'
    ,@subject = 'MY_SUBJECT'
    ,@body = 'This is a test'
    ,@attach_query_result_as_file = 1
    ,@query_attachment_filename = 'file.csv'
    ,@query_result_separator = '    '
    ;

附加文件始终为空。我在外面尝试了我的查询sp_send_dbmail,它运行良好。我还尝试替换我的查询SELECT 1,然后我的附件中有数据。

什么可能导致我的查询不返回任何数据?

4

1 回答 1

1

我找到了解决方法。我必须在表名之前指定数据库。更像是:

EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'MY_PROFILE'
    ,@recipients = 'MY_EMAIL_ADDRESS'
    ,@query = 'SELECT TOP 50 FIELD1, FIELD2, FIELD3 FROM DATABADE.dbo.TABLE1'
    ,@subject = 'MY_SUBJECT'
    ,@body = 'This is a test'
    ,@attach_query_result_as_file = 1
    ,@query_attachment_filename = 'file.csv'
    ,@query_result_separator = '    '
    ;
于 2013-09-05T14:58:58.687 回答