I'm trying to send an email using sp_send_dbmail
. I need it to send one query as an attachment and another as part of the body of the email. The problem is that sp_send_dbmail
only has one @query parameter, and I can't see any way to add another one.
Is there any way to either a) add a second query (with all of the parameters attached to it) or b) execute the query into a variable and then add that to the body of my email?
I'm using sql-server 2005.
TIA!
Use the
@query
parameter of the stored proceduremsdb.dbo.sp_send_dbmail
for the attachment and use the@body
parameter with a variable that contains the result of the other query.The example code below creates a string from SQL Server job step history that contains HTML table elements used to send an email using the stored procedure
msdb.dbo.sp_send_dbmail
. You should be able to adapt it for your purposes.