SQL Server 2008 - Determine Which SQL Agent Job Runs the Stored Procedure

Is there a way to determine which SQL agent job executes the stored procedure?

The reason I want it is because I would like to have a separate step that is executed on failure, which stores a procedure that will send a log file by email. To get the log file (we always use only one log file for each job, not per step), I would just like to get the log file by querying the MSDB tables ( select output_file_name from sysjobsteps ).

I can pass the parameter with the name of the job to the stored procedure, but I would not want to do this.

Any ideas?

thanks!

+4
source share
1 answer

Do you mean what task causes the logging procedure? those. who is calling me, is that what you mean? if so, then it may be relevant ... SQL Server Agent - get my own job_id . The rejection step at which you publish your registration process can use the extracted jobid according to the method described in the link ... imho will work .. you need to add the job identifier, though .. and each rejection step in each job would have to have two strings ... one to get the identifier and one to call proc.

+1
source

All Articles