Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Invoked Schedule Id of the Job : Urgent!


Invoked Schedule Id of the Job : Urgent!

Author
Message
winash
winash
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1424 Visits: 1883
I seem to understand what you are looking for...however I can't find any tables that store the schedule id from which a job is invoked...

There is a table - msdb.dbo.sysjobactivity - that stores a record for each job during the job execution (as long as the stop_execution_date is not null for a job in this table the job is currently executing).

I tried to see if there is any way to get the schedule that invoked the job when it is being executed but couldn't find anything - except for the horrible hacked code below which I am only attaching as I worked on it for the past hour :-P

The result of this code (best viewed by setting results to text) will display the name of the schedule and schedule id the job is invoked from (while the job is running)

And finally - I have no clue if this is going to help you in any way... Ermm



/*

IMPORTANT: Creates a job called TestJob1 (and deletes any existing job with that name first)
This job will keep running at intervals of 10 and 23 seconds
This code will keep running
Stopping the code will not delete the job - it will still be running - delete the job after stopping the execution

*/
-- make the job wait for the specified delay and then do some very
-- meaningful thing like selecting the current date
DECLARE @JobSql nvarchar(max),@Delay varchar(12);
SET @Delay = '00:00:05';
SET @JobSql = 'WAITFOR DELAY '+QUOTENAME(@Delay,'''');
SET @JobSql = @JobSql + CHAR(13)+CHAR(10)+'SELECT getdate()';

DECLARE @JobCmd varchar(200) = @JobSql;
-- SET YOUR SERVER NAME HERE!!!
DECLARE @srvname sysname = '<>';

IF EXISTS(SELECT 1 FROM msdb.dbo.sysjobs WHERE name = 'TestJob1')
BEGIN
PRINT 'Deleting job';
EXEC msdb.dbo.sp_delete_job @job_name = 'TestJob1';
END
PRINT 'Creating job';
EXEC msdb.dbo.sp_add_job @job_name = 'TestJob1',@owner_login_name='sa';
EXEC msdb.dbo.sp_add_jobstep @job_name='TestJob1',@step_name = 'Step1',@command=@JobCmd;
EXEC msdb.dbo.sp_add_jobserver @job_name='TestJob1',@server_name=@srvname;
-- 10 second interval schedule
EXEC msdb.dbo.sp_add_jobschedule @job_name='TestJob1', @name='TestJob1_Sched10Second',
@enabled=1, @freq_type=4, @freq_interval=1, @freq_subday_type=2, @freq_subday_interval=10;
-- 23 second interval schedule
EXEC msdb.dbo.sp_add_jobschedule @job_name='TestJob1', @name='TestJob1_Sched23Second',
@enabled=1, @freq_type=4, @freq_interval=1, @freq_subday_type=2, @freq_subday_interval=23;


DECLARE @jobname sysname,@jobid uniqueidentifier,@joboutcomemsg nvarchar(1024);
SET @jobname = 'TestJob1';
SELECT @jobid = job_id FROM msdb.dbo.sysjobs WITH (NOLOCK) WHERE name = @jobname;
WHILE(1=1)
BEGIN
WHILE EXISTS(SELECT 1 FROM msdb.dbo.sysjobactivity WHERE job_id = @jobid)
BEGIN
IF ((SELECT stop_execution_date FROM msdb.dbo.sysjobactivity WHERE job_id = @jobid )IS NOT NULL)
BEGIN
IF (@joboutcomemsg IS NOT NULL)
SELECT 'Before Break',@joboutcomemsg JobOutcomeMessage;

WAITFOR DELAY '00:00:01'
BREAK -- job has completed - break out
END
ELSE
BEGIN
SELECT @joboutcomemsg = last_outcome_message FROM msdb.dbo.sysjobactivity T1 INNER JOIN msdb.dbo.sysjobservers T2 ON
T1.job_id = T2.job_id
WHERE T1.job_id = @jobid
IF (@joboutcomemsg IS NOT NULL)
SELECT 'During continue',@joboutcomemsg JobOutcomeMessage;

WAITFOR DELAY '00:00:01'
CONTINUE -- continue waiting
END
END
END;






Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24187 Visits: 37955
I didn't forget, I just spent most of last night figuring out a problem I was having here at work. Hopefully tonight I may get some time to look into this.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
ganeshmuthuvelu
ganeshmuthuvelu
SSC Journeyman
SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)

Group: General Forum Members
Points: 90 Visits: 305
Thanks for the update.. I will wait to hear from you.



x_japanfans5312
x_japanfans5312
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 Visits: 209
Hi, i also facing this problem, is there any solution for this ?
pateldhruvb
pateldhruvb
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 17
Hi, Have you find solution to get schedule ID when its running as I have facing exact same problem,you were facing.
can you please share your solution?

Thanks in advance,
Brian Stover
Brian Stover
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 183
I'm also having this problem on SQL 2008 R2. You could write an ugly parsing procedure to extract the schedule_id from the message field in the stepid=0 record of sysjobhistory after the job has ran. That's the closest I've been able to come up with.
ganeshmuthuvelu
ganeshmuthuvelu
SSC Journeyman
SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)

Group: General Forum Members
Points: 90 Visits: 305
Lynn,
Did you get a chance to find this out? This is still a problem for me..

Thanks.



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search