0

I am calling sp_send_dbmail and setting the query parameter. The resulting email includes the results of the query. I want the actual query (the value of the query parameter) to be appended to the email, so that the email will include the results and then the query itself at the end.

This will aid debugging.

cja
  • 9,512
  • 21
  • 75
  • 129
  • What happens when you pass the same value to both @query and @body? – Eric J. Price Feb 22 '13 at 16:13
  • The value of body appears before the results of executing the value of query. I want it the other way around. – cja Feb 22 '13 at 16:16
  • 1
    Yeah, that's what I figured. You can't do it easily, but you can do a weird hack to make it work. You'd have to perform the query logic and pass the results in as the body and then use the query to return an Nvarchar representation of your query. Check out this post http://stackoverflow.com/questions/4808340/how-can-i-use-sp-send-dbmail-to-send-multiple-queries it's your only real option to do what your asking to do, but you could easily do it with SSRS report if that is an option. – Eric J. Price Feb 22 '13 at 16:20

0 Answers0