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, October 9, 2014 1:19 PM
Points: 327, Visits: 587
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


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 7:08 AM
Points: 943, Visits: 2,950
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