I have stored procedure usp_emailRecipients
that returns a semicolon-delimited list of email addresses. This is the list of email addresses that will receive an email sent using msdb.dbo.sp_send_dbmail
.
How can I set the value of @recipients
to the list returned in my stored procedure?
I cannot modify the stored procedure at the moment.
Something like:
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Bob Jones',
@recipients = 'exec usp_emailRecipients',
@subject = 'Test email',
@execute_query_database = 'Sales',
@query = N'select * from sales',
@attach_query_result_as_file = 1,
@query_attachment_filename = 'Sales.txt'
Thanks.