Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Job Instance ID Expand / Collapse
Author
Message
Posted Friday, October 26, 2012 8:25 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, December 11, 2014 11:23 AM
Points: 337, Visits: 598
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).
Post #1377624
Posted Tuesday, October 30, 2012 5:33 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 1:44 AM
Points: 1,001, Visits: 3,091
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

@SeanPearceSQL

About Me
Post #1378701
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse