sqlsql-serverdbmail

Sql server Db Mail which can send mail for two or more queries


I want to send db mail , which contains the result of two queries, how do I make it happen?

USE msdb
EXEC sp_send_dbmail
  @profile_name = 'try01',
  @recipients = 'yyyyy@yyy.com',
  @subject = 'Table Values',
  @body = 'xxxxxxxxxxxxxx.',
  @execute_query_database = 'Reports',
  @query = 'SELECT * from Table'

Solution

  • OK, This was easy as if you put a semicolon the result of both the queries are sent. Here it is:

    USE msdb
    EXEC sp_send_dbmail
      @profile_name = 'try01',
      @recipients = 'yyyyy@yyy.com',
      @subject = 'Table Values',
      @body = 'xxxxxxxxxxxxxx.',
      @execute_query_database = 'Reports',
      @query = 'SELECT * from Table; select * from table2'
    

    Only problem I have now is to get this into a decent looking format.