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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How does one call a Job name?

Author  Topic 

drewsalem
Constraint Violating Yak Guru

304 Posts

Posted - 2006-01-12 : 09:46:59
In the same way that the function @@Servername calls the name of the server, can the name of the Job that fired up the T-SQL be called? In fact, can any job be referenced at all?

Cheers,

Drew

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-01-12 : 13:23:39
You can start and stop jobs with the system stored procedures: sp_start_job, sp_stop_job. If that doesn't answer your question, please let us know as I'm a bit confused.

Tara Kizer
aka tduggan
Go to Top of Page

druer
Constraint Violating Yak Guru

314 Posts

Posted - 2006-01-12 : 14:30:04
I think Drew is asking if there is a way to determine what job it was that invoked a T-sql statement.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-01-12 : 14:32:48
Then the answer is only if you had SQL Profiler running.

Tara Kizer
aka tduggan
Go to Top of Page

drewsalem
Constraint Violating Yak Guru

304 Posts

Posted - 2006-01-12 : 15:21:52
Thanks for the replies.

Every job on the server consist of 2 Steps.

Step 1: Do the thing. On Success, chill. On failure, Go To Next Step.
Step 2: Exec sp_FailedJob

sp_FailedJob is a stored procedure that is fired up if a job fails. This stored procedure sends an email out to let me know that a job has failed. The email says something along the lines of 'A job has failed, sexy, on the server ' + @@servername.

The number of jobs will increase significantly over the next few months and the boss has asked that the email specify the job that has failed. So, is there a way to say 'The job ' + job_name(?) + ' has failed on the server ' + @@servername.

Thanks

Drew
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-01-12 : 15:25:28
The only way that I know of to find out if it failed is to look at sysjobs in msdb.

Tara Kizer
aka tduggan
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-01-12 : 15:50:34
You might want to consider using the job notifications instead of the sp_FailedJob, which would mean SQL Server would handle it for you. But it would also mean needing to set this up per job.

Or another thought is to have a job that only runs sp_FailedJob and sends out each of the failed jobs found in sysjobs.

Tara Kizer
aka tduggan
Go to Top of Page

drewsalem
Constraint Violating Yak Guru

304 Posts

Posted - 2006-01-12 : 16:07:44
Wow. Thanks. I'll have a think about that.
Go to Top of Page
   

- Advertisement -