sp_send_dbmail set 2 queries for the @query parameter


May i ask is it possible to set two queries for the stored procedure sp_send_dbmail?

  • How to find max of one column of all child in SQL
  • Stored procedure returning null value to parameter during creating a new user
  • Which are necessary steps to connect to an Azure SQL database in Visual Studio or SQL Server Management Studio?
  • Showing the result of COALESCE into separate columns based from where they where retrieved
  • T-SQL query update null values
  • I am confused in two ways to create one to many relationship in code first migration . Which one to choose?
  • For example:

    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 ;  

    Since most of the example from the internet only contain one query for the @query parameter.

    May i ask will the above code causing error?

    Thanks a lot !!


    After deployment, the script was result in error for the @query parameter defined.

    The error message is shown below

    Error formatting query, probably invalid parameters [SQLSTATE 42000] (Error 22050). The step failed.


    Notice that when defining @query, the table should be in full path,


    @query = ‘Select * from [YOUR_SERVER_NAME].[dbo].table1; Select * from [YOUR_SERVER_NAME].[dbo].table2;’,

  • Formatting query data in HTML email from SQL Server 2008
  • sp_send_dbmail keep sending email
  • SQL Server SP_SEND_DBMAIL Image file attachment
  • Using sp_send_dbmail with recieptent and content from single sql row
  • How to specify the reply-to address using sp_send_dbmail in SQL Server
  • Sending Email in SQL Server 2008 R2
  • One Solution collect form web for “sp_send_dbmail set 2 queries for the @query parameter”

    I tried .
    It did work, but the result was in same file. Not sure if thats what you want.
    Plus the number of rows is also an issue. Or error as follows is shown:

     Msg 22050, Level 16, State 1, Line 0
    File attachment or query results size exceeds allowable value of 1000000 bytes.
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.