我在 SQL Server 2008 中使用 sp_send_dbmail 发送查询结果。我将查询移动到一个过程中,并尝试在 sp_send_dbmail 过程中使用该过程,如下所示:
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'myprofile',
@from_address = '[email protected] /cdn-cgi/l/email-protection',
@reply_to = '[email protected] /cdn-cgi/l/email-protection',
@recipients = '[email protected] /cdn-cgi/l/email-protection',
@importance = 'NORMAL',
@sensitivity = 'NORMAL',
@subject = 'My Subject',
@body = 'Here you go.',
@attach_query_result_as_file= 1,
--@query_result_header = 1,
@query_result_width = 1000,
@query_result_separator = '~',
@query_attachment_filename = 'myFile.txt',
@query = 'EXEC dbo.myProc'
我也尝试过在 proc 上使用 4 部分命名;有和没有“EXEC”等。它作为查询工作得很好,但我似乎无法让它作为过程工作。这可能吗?
您需要添加数据库上下文:
@execute_query_database = 'MyDatabaseName',
我刚刚在 AdventureWorks 2008 上运行了这个,没有任何问题:
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'DBMail',
@recipients = '[email protected] /cdn-cgi/l/email-protection',
@query = 'exec dbo.uspGetManagerEmployees 5' ,
@execute_query_database = 'AdventureWorks2008',
@subject = 'Work Order Count',
@attach_query_result_as_file = 1 ;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)