Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
LanceS
Starting Member
5 Posts |
Posted - 2004-01-27 : 17:14:56
|
I am trying the the variable @thisjobStatus from a ystem stored proc to find our if the job is idle. I can get the stored proc to return the proper result set but don't know how to get the value of the current_execution_status into the variable. Your help is very apprieciated. Here is the current script please help me finish it.DECLARE @thisjobStatus INT, @thisJobID UNIQUEIDENTIFIERSELECT @thisJobID = job_id FROM msdb..SysJobs WHERE Name = 'MyDTS'EXECUTE msdb..sp_get_composite_job_info @thisJobID SELECT @thisjobStatus = NULLWHILE @thisjobStatus <> 4BEGIN EXECUTE msdb..sp_get_composite_job_info @thisJobID SET @thisJobStatus = current_execution_status (from the sp_)ENDPRINT @thisJobStatus |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-01-27 : 17:18:27
|
You need to put the results of the stored procedure into a temp table:CREATE TABLE #Temp()INSERT INTO #TempEXEC msdb..sp_get...SELECT @thisJobStatus = current_execution_statusFROM #TempWHERE...DROP TABLE #TempTara |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
LanceS
Starting Member
5 Posts |
Posted - 2004-01-27 : 17:38:27
|
When I do that I get the following error:An INSERT EXEC statement cannot be nested.Here is the full script:DECLARE @thisjobStatus INT, @thisRowCount INT, @thisJobID UNIQUEIDENTIFIER, @thisSQL VARCHAR(5000)SELECT @thisJobID = job_id FROM msdb..SysJobs WHERE Name = 'MyDTS'CREATE TABLE #temp(job_id UNIQUEIDENTIFIER, originating_server VARCHAR(100), name sysname, enabled int , description VARCHAR(100), start_step_id INT, category VARCHAR(100), owner VARCHAR(100), notify_level_eventlog INT, notify_level_email INT, notify_level_netsend INT, notify_level_page INT, notify_email_operator INT, notify_netsend_operator INT, notify_page_operator INT, delete_level INT, date_created DATETIME, date_modified DATETIME, version_number INT, last_run_date VARCHAR(100), last_run_time VARCHAR(100), last_run_outcome INT, next_run_date INT, next_run_time INT, next_run_schedule_id INT, current_execution_status INT, current_execution_step VARCHAR(100), current_retry_attempt INT, has_step INT, has_schedule INT, has_target INT, type INT)INSERT INTO #TempEXECUTE msdb..sp_get_composite_job_info @thisJobIDSELECT @thisjobStatus = current_execution_status FROM #TempPRINT @thisJobStatus |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-01-27 : 17:41:28
|
Yep, can't use the temp table. Check out the link that I posted.Tara |
|
|
LanceS
Starting Member
5 Posts |
Posted - 2004-01-29 : 14:25:29
|
Thanks Tara I found another way around this.In case it helps anyone else:SELECT @thisJobID = job_id FROM msdb..SysJobs WHERE Name = @thisDTSSELECT @thisInitDate = run_Date, @thisInitTime = run_timeFROM msdb..sysjobhistoryWHERE Job_ID = @thisJobID AND Instance_ID = (SELECT MAX(Instance_ID) FROM msdb..sysjobhistory WHERE Job_ID = @thisJobID)EXEC msdb..sp_start_job @job_name = @thisDTSSELECT @thisNewDate = @thisInitDate, @thisNewTime = @thisInitTimePRINT @thisInitDatePRINT @thisInitTime WHILE @thisInitDate = @thisNewDate AND @thisInitTime = @thisNewTime BEGIN SELECT @thisNewDate = run_Date , @thisNewTime = run_time FROM msdb..sysjobhistory WHERE Job_ID = @thisJobID AND Instance_ID = (SELECT MAX(Instance_ID) FROM msdb..sysjobhistory WHERE Job_ID = @thisJobID) END |
|
|
SMerrill
Posting Yak Master
206 Posts |
Posted - 2007-04-06 : 15:56:31
|
Tara, your link is expired. what is that reference?~ Shaun MerrillSeattle, WA |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-04-06 : 16:09:10
|
quote: Originally posted by SMerrill Tara, your link is expired. what is that reference?~ Shaun MerrillSeattle, WA
I have no idea. It was 3 years ago!Tara Kizerhttp://weblogs.sqlteam.com/tarad/ |
|
|
|
|
|
|
|