Job Instance ID

  • Does anyone know if there is a function [like getdate()] that you can use to get the Job's instance ID, if the stored proc is running under a Job? The only way I know would be to do a search on the Job and Max(instance_ID).

  • This code will get the value when run in a job.

    DECLARE @MaxID INT;

    SELECT @MaxID = MAX(instance_id)

    FROM [msdb].[dbo].[sysjobhistory]

    WHERE job_id = CONVERT(uniqueidentifier, $(ESCAPE_NONE(JOBID)))

    AND step_id = 1;

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

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