title: Passing stored procedure to sp_send_dbmail
body: <p>I am using sp_send_dbmail in SQL Server 2008 to send out the results of a query. I moved the query into a proc and am trying to use the proc in the sp_send_dbmail prcedure like so:</p>
  
  <pre><code>EXEC msdb.dbo.sp_send_dbmail 
  @profile_name               = 'myprofile',
  @from_address               = 'email@somedomain.com',
  @reply_to                   = 'email@somedomain.com',
  @recipients                 = 'email@differentdomain.com',  
  @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'
  </code></pre>
  
  <p>I have also tried this using 4 part naming on the proc; with and without the 'EXEC', etc. It worked fine as a query, but I cannot seem to get it to work as a proc. Is this even possible?</p>