title: sp_send_dbmail set 2 queries for the @query parameter
body: <p>all</p>
  
  <p>May i ask is it possible to set two queries for the stored procedure sp_send_dbmail?</p>
  
  <p>For example:</p>
  
  <pre><code>EXEC msdb.dbo.sp_send_dbmail  
  @profile_name = 'example',  
  @recipients = 'example@XXX.com',  
  @query = 'Select * from table1; Select * from table2;',  
  @subject = 'Example',  
  @attach_query_result_as_file = 1 ;  
  </code></pre>
  
  <p>Since most of the <a href="https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-send-dbmail-transact-sql" rel="nofollow noreferrer">example</a> from the internet only contain one query for the @query parameter.</p>
  
  <p>May i ask will the above code causing error?</p>
  
  <p>Thanks a lot !!</p>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>After deployment, the script was result in error for the @query parameter defined.</p>
  
  <p>The error message is shown below</p>
  
  <blockquote>
    <p>Error formatting query, probably invalid parameters [SQLSTATE 42000] (Error 22050).  The step failed.</p>
  </blockquote>
  
  <p>Solution:</p>
  
  <p>Notice that when defining @query, the table should be in full path,</p>
  
  <p>Hence:</p>
  
  <blockquote>
    <p>@query = 'Select * from [YOUR_SERVER_NAME].[dbo].table1; Select * from [YOUR_SERVER_NAME].[dbo].table2;',  </p>
  </blockquote>