title: sp_send_dbmail fails with attachment
body: <p>I need to send email with file attachments. The attachment has to come from image type data field. When running the following code in both a query window and also stored procedure, no email is sent. in query window, it just says 'command(s) completed successfully', but no email. </p>
  
  <pre><code>EXEC  msdb.dbo.sp_send_dbmail @recipients = 'xx@xx.com',
      @subject = 'test',
      @execute_query_database = 'myDB',
      @body = 'test',
      @body_format = 'HTML', 
      @profile_name = 'myProfile',
      @append_query_error = 1,
      @query = 'Select docData from [myDB].[dbo].[Documents] Where id = 1',
      @query_result_header = 0,
      @attach_query_result_as_file = 1,
      @query_attachment_filename = 'Test.doc',
      @exclude_query_output = 1,
      @query_no_truncate = 1;
  </code></pre>
  
  <p>The email is send when I remove @query:</p>
  
  <pre><code>EXEC  msdb.dbo.sp_send_dbmail @recipients = 'xx@xx.com',
      @subject = 'test',
      @execute_query_database = 'myDB',
      @body = 'test',
      @body_format = 'HTML', 
      @profile_name = 'myProfile';
  </code></pre>
  
  <p>But I need the attachments code to work. Any help would be greatly appreciated. </p>