Wednesday, March 7, 2012

Getting Job name, Job ID , Step within the Job

Hi There,
Can I get the Job ID , Job name and Step ID withing the job itself ? Infact
my need is to send a mail with these parameters and some data from user
tables. This process I have to do from the different servers and jobs. I
would like to impliment this without hardcoding the job names , Job ID etc.
Thank you,
ShinuPlease post DDL, sample data and expected result. If I understand your
question correctly, then I see no reason why this question would ever need t
o
be asked.
ML
http://milambda.blogspot.com/|||Hi ,
Thank you
I just want to get the name of the Job and Job ID within a step of the same
job and mail it.
Eg: In step 1 of the job1 I need to send a mail
EXEC msdb.dbo.SP_Send_DBMail @.Profile_Name = 'MyProfile',
@.Recipients = 'Myname@.MyCompany.com',
@.Body = @.job,
@.Subject = @.@.Servername
Regards,
Shinu
"ML" wrote:

> Please post DDL, sample data and expected result. If I understand your
> question correctly, then I see no reason why this question would ever need
to
> be asked.
>
> ML
> --
> http://milambda.blogspot.com/|||To put it as simple as possible: concatenate the values you want to send in
the body of the e-mail message into a single varchar variable or use the
@.query parameter to specify a query whose result set can either be sent as a
n
attachment or a part of the body.
ML
http://milambda.blogspot.com/|||Hi ,
How can I get the jobname and Job ID within the job ?
Thanks
Shinu
"ML" wrote:

> To put it as simple as possible: concatenate the values you want to send i
n
> the body of the e-mail message into a single varchar variable or use the
> @.query parameter to specify a query whose result set can either be sent as
an
> attachment or a part of the body.
>
> ML
> --
> http://milambda.blogspot.com/|||What exactly are you trying to achieve? Are you designing a procedure that
will send messages as SQL Server Jobs are being run, that can be used in
several of your jobs?
Look at the sysjobs system table (in the msdb database).
ML
http://milambda.blogspot.com/|||My guess is that Shinu want to receive an email with the name of the job, wh
ether the job was OK,
the ID of the job etc. I do this all the time.
Shinu, you can use Agent tokens for this. The syntax for token differs betwe
en 2000 and 2005. If you
search Books Online for below, you will find more information:
token agent
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"ML" <ML@.discussions.microsoft.com> wrote in message
news:36337B02-D5C6-4F0B-827C-A55BA5A39380@.microsoft.com...
> What exactly are you trying to achieve? Are you designing a procedure that
> will send messages as SQL Server Jobs are being run, that can be used in
> several of your jobs?
> Look at the sysjobs system table (in the msdb database).
>
> ML
> --
> http://milambda.blogspot.com/|||Ah, you mean using the COMMAND parameter of the sp_add_jobstep system
procedure?
ML
http://milambda.blogspot.com/|||Use tokens.
http://www.sqldev.net/sqlagent/SQLAgentStepTokens.htm
"Shinu" <Shinu@.discussions.microsoft.com> wrote in message
news:433ECE5A-A3FB-45A9-930F-9019B4910343@.microsoft.com...
> Hi There,
> Can I get the Job ID , Job name and Step ID withing the job itself ?
> Infact
> my need is to send a mail with these parameters and some data from user
> tables. This process I have to do from the different servers and jobs. I
> would like to impliment this without hardcoding the job names , Job ID
> etc.
> Thank you,
> Shinu
>
>

No comments:

Post a Comment