SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to retrieve value from msdb.dbo.sp_help_job


how to retrieve value from msdb.dbo.sp_help_job

Author
Message
DKG-967908
DKG-967908
Mr or Mrs. 500
Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)

Group: General Forum Members
Points: 561 Visits: 239
Hi All,

I have created a stored procedure with a int parameter - if user passes 0 it will stop a particular job and disable it (as per users requirement) and if user passes 1 it will enable that particular job.

I have done with SP and its working fine. The only issue is i have used Openrowset is my stored procedure to get a current status of that job:

declare @status int

set @status = (select last_run_outcome from openrowset

('SQLOLEDB','Server=(local);Trusted_Connection=yes','SET FMTONLY OFF EXEC msdb.dbo.sp_help_job') q

where name = 'test job')

By some reason i cannt use openrowset here.

Is anyone can help me getting a different method to capture a value from sp_help_job.

An early reply would be appreciated.

Thanks,
DKG
Adiga
Adiga
SSCertifiable
SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)

Group: General Forum Members
Points: 6194 Visits: 21012
You may find this script useful.

Pradeep Adiga
Blog: sqldbadiaries.com
Twitter: @pradeepadiga
AlexSQLForums
AlexSQLForums
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3552 Visits: 2283
DKG-967908 (1/11/2011)
Hi All,

I have created a stored procedure with a int parameter - if user passes 0 it will stop a particular job and disable it (as per users requirement) and if user passes 1 it will enable that particular job.

I have done with SP and its working fine. The only issue is i have used Openrowset is my stored procedure to get a current status of that job:

declare @status int

set @status = (select last_run_outcome from openrowset

('SQLOLEDB','Server=(local);Trusted_Connection=yes','SET FMTONLY OFF EXEC msdb.dbo.sp_help_job') q

where name = 'test job')

By some reason i cannt use openrowset here.

Is anyone can help me getting a different method to capture a value from sp_help_job.

An early reply would be appreciated.

Thanks,
DKG

That's because sp_help_job is not a table. it's a stored procedure.
You can use linked server queries to retrieve job status from other servers as long as the login has administrative rights.
Lookup sysjobhistory in Books Online.

Alex S
DKG-967908
DKG-967908
Mr or Mrs. 500
Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)

Group: General Forum Members
Points: 561 Visits: 239
Thanks Adiga and Alex for your response, Adiga that script is good but not solving my purpose :-( .

Alex there must be some way to get a value from sp_help_job (variable or temp table). I am not very good in scripting that’s why struggling.


thanks,
DKG
AlexSQLForums
AlexSQLForums
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3552 Visits: 2283
DKG-967908 (1/11/2011)
Thanks Adiga and Alex for your response, Adiga that script is good but not solving my purpose :-( .

Alex there must be some way to get a value from sp_help_job (variable or temp table). I am not very good in scripting that’s why struggling.


thanks,
DKG

DKG i was wrong about sp_help_job it turns out it does work and i was able to get a status of a job.
See if running these commands help:
------------------------------
sp_configure 'show advanced options', 1
go
reconfigure with override
go
sp_configure 'Ad Hoc Distributed Queries', 1
go
reconfigure with override
go

------------------------------

declare @runstatus int
set @runstatus = (select last_run_outcome
from
openrowset ('SQLOLEDB','Server=(local);Trusted_Connection=yes','SET FMTONLY OFF EXEC msdb.dbo.sp_help_job') q
where name = '')
print @runstatus

Alex S
DKG-967908
DKG-967908
Mr or Mrs. 500
Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)

Group: General Forum Members
Points: 561 Visits: 239
Alex you didn't understand...the code I have mentioned (posted by me initially) working perfectly fine. The only issue is that I cant use (means I don’t want to use) openrowset. That’s why I am looking for some other work around.

cheers!
DKG
Spindrift
Spindrift
SSC Eights!
SSC Eights! (815 reputation)SSC Eights! (815 reputation)SSC Eights! (815 reputation)SSC Eights! (815 reputation)SSC Eights! (815 reputation)SSC Eights! (815 reputation)SSC Eights! (815 reputation)SSC Eights! (815 reputation)

Group: General Forum Members
Points: 815 Visits: 310
I have the exact same issue - not been able to find a workaround :-/
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