Email results of Stored Procedure problem

  • Hello,

         I feel like I am missing something obvious here.

         I have a scheduled job that runs a tsql step that executes XP_sendmail with a stored procedure as the @query parameter. This works fine as long as the stored procedure only returns one record set.

         I need to modify the stored procedure to run another query and return those results as well. When I execute the stored procedure, it only returns the first recordset (when I run the code ad hoc, I get two result sets). I cannot use the UNION operator, because the results are not in the same format.

         Is there a way to get this stored procedure to return both result sets so I can send out only one email?

     

     

  • EXEC xp_sendmail 'test', @query = 'select * from sysdatabases select * from syslogins'

  • I guess I wasn't very clear. I'd like to sp to return several record sets. I could put the individual SQL statements into a t-sql set on a job, but I'd rather have them in a SP for the usual reasons (reuse, code management, etc.).

    Is there a way to do this?

  • For example, EXEC xp_sendmail 'Test', @query = 'exec sp_helpdb exec sp_helplogins'

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply