How can I get the current job's name or job ID from a job step within
the job in sql server?In MSDB, start checking out the sysjobs, sysjobssteps, etc. tables.
"tram" <tram_e@.hotmail.com> wrote in message
news:1104250803.810521.121410@.z14g2000cwz.googlegroups.com...
> How can I get the current job's name or job ID from a job step within
> the job in sql server?
>|||Chris,
I know the the tablenames, but we need to give either job ID or name to
get the output file name. After finishing step1, I should be able to
get the output fielname of step1 for current job without hard coding
...
ChrisR wrote:
> In MSDB, start checking out the sysjobs, sysjobssteps, etc. tables.
>
> "tram" <tram_e@.hotmail.com> wrote in message
> news:1104250803.810521.121410@.z14g2000cwz.googlegroups.com...
> > How can I get the current job's name or job ID from a job step
within
> > the job in sql server?
> >|||Chris,
I know the the tablenames, but we need to give either job ID or name to
get the output file name. After finishing step1, I should be able to
get the output fielname of step1 for current job without hard coding
...
ChrisR wrote:
> In MSDB, start checking out the sysjobs, sysjobssteps, etc. tables.
>
> "tram" <tram_e@.hotmail.com> wrote in message
> news:1104250803.810521.121410@.z14g2000cwz.googlegroups.com...
> > How can I get the current job's name or job ID from a job step
within
> > the job in sql server?
> >|||Perhaps this is of help?
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"tram" <tram_e@.hotmail.com> wrote in message
news:1104252327.066933.268140@.f14g2000cwb.googlegroups.com...
> Chris,
> I know the the tablenames, but we need to give either job ID or name to
> get the output file name. After finishing step1, I should be able to
> get the output fielname of step1 for current job without hard coding
> ...
>
> ChrisR wrote:
>> In MSDB, start checking out the sysjobs, sysjobssteps, etc. tables.
>>
>> "tram" <tram_e@.hotmail.com> wrote in message
>> news:1104250803.810521.121410@.z14g2000cwz.googlegroups.com...
>> > How can I get the current job's name or job ID from a job step
> within
>> > the job in sql server?
>> >
>|||Use the [JOBID] job step token. See sp_add_job_step in BOL for details. Also
look at http://sqldev.net/sqlagent/SQLAgentStepTokens.htm
--
HTH
Jasper Smith (SQL Server MVP)
http://www.sqldbatips.com
I support PASS - the definitive, global
community for SQL Server professionals -
http://www.sqlpass.org
"tram" <tram_e@.hotmail.com> wrote in message
news:1104250803.810521.121410@.z14g2000cwz.googlegroups.com...
> How can I get the current job's name or job ID from a job step within
> the job in sql server?
>|||Jasper,
I've tried using token. But didn't work. Would you give an example?
Thanks
Jasper Smith wrote:
> Use the [JOBID] job step token. See sp_add_job_step in BOL for
details. Also
> look at http://sqldev.net/sqlagent/SQLAgentStepTokens.htm
> --
> HTH
> Jasper Smith (SQL Server MVP)
> http://www.sqldbatips.com
> I support PASS - the definitive, global
> community for SQL Server professionals -
> http://www.sqlpass.org
> "tram" <tram_e@.hotmail.com> wrote in message
> news:1104250803.810521.121410@.z14g2000cwz.googlegroups.com...
> > How can I get the current job's name or job ID from a job step
within
> > the job in sql server?
> >|||Did you check the samples at the web page that Jasper and me posted?
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"tram" <tram_e@.hotmail.com> wrote in message
news:1104265806.678523.298020@.z14g2000cwz.googlegroups.com...
> Jasper,
> I've tried using token. But didn't work. Would you give an example?
> Thanks
>
> Jasper Smith wrote:
>> Use the [JOBID] job step token. See sp_add_job_step in BOL for
> details. Also
>> look at http://sqldev.net/sqlagent/SQLAgentStepTokens.htm
>> --
>> HTH
>> Jasper Smith (SQL Server MVP)
>> http://www.sqldbatips.com
>> I support PASS - the definitive, global
>> community for SQL Server professionals -
>> http://www.sqlpass.org
>> "tram" <tram_e@.hotmail.com> wrote in message
>> news:1104250803.810521.121410@.z14g2000cwz.googlegroups.com...
>> > How can I get the current job's name or job ID from a job step
> within
>> > the job in sql server?
>> >
>|||Tibor,
I appreciate your reply. I've seen the examples , but is not working. I
was trying to know the JOB id of current job in the job step so that I
can get the output file name from sysjobsteps.
Anyway, thanks for your reply.
Tibor Karaszi wrote:
> Did you check the samples at the web page that Jasper and me posted?
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "tram" <tram_e@.hotmail.com> wrote in message
> news:1104265806.678523.298020@.z14g2000cwz.googlegroups.com...
> > Jasper,
> >
> > I've tried using token. But didn't work. Would you give an example?
> >
> > Thanks
> >
> >
> >
> > Jasper Smith wrote:
> >> Use the [JOBID] job step token. See sp_add_job_step in BOL for
> > details. Also
> >> look at http://sqldev.net/sqlagent/SQLAgentStepTokens.htm
> >>
> >> --
> >> HTH
> >>
> >> Jasper Smith (SQL Server MVP)
> >> http://www.sqldbatips.com
> >> I support PASS - the definitive, global
> >> community for SQL Server professionals -
> >> http://www.sqlpass.org
> >>
> >> "tram" <tram_e@.hotmail.com> wrote in message
> >> news:1104250803.810521.121410@.z14g2000cwz.googlegroups.com...
> >> > How can I get the current job's name or job ID from a job step
> > within
> >> > the job in sql server?
> >> >
> >|||tram,
"Doesn't work" is not a very good problem description. I created a job with one jobstep and added
below SQL to the jobstep. Work just fine on my machine:
SELECT 'The output file name is "' + output_file_name + '"'
FROM msdb..sysjobsteps
WHERE job_id = [JOBID]
AND step_id = [STEPID]
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"tram" <tram_e@.hotmail.com> wrote in message
news:1104323486.443287.4420@.z14g2000cwz.googlegroups.com...
> Tibor,
> I appreciate your reply. I've seen the examples , but is not working. I
> was trying to know the JOB id of current job in the job step so that I
> can get the output file name from sysjobsteps.
> Anyway, thanks for your reply.
>
> Tibor Karaszi wrote:
>> Did you check the samples at the web page that Jasper and me posted?
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://www.solidqualitylearning.com/
>> http://www.sqlug.se/
>>
>> "tram" <tram_e@.hotmail.com> wrote in message
>> news:1104265806.678523.298020@.z14g2000cwz.googlegroups.com...
>> > Jasper,
>> >
>> > I've tried using token. But didn't work. Would you give an example?
>> >
>> > Thanks
>> >
>> >
>> >
>> > Jasper Smith wrote:
>> >> Use the [JOBID] job step token. See sp_add_job_step in BOL for
>> > details. Also
>> >> look at http://sqldev.net/sqlagent/SQLAgentStepTokens.htm
>> >>
>> >> --
>> >> HTH
>> >>
>> >> Jasper Smith (SQL Server MVP)
>> >> http://www.sqldbatips.com
>> >> I support PASS - the definitive, global
>> >> community for SQL Server professionals -
>> >> http://www.sqlpass.org
>> >>
>> >> "tram" <tram_e@.hotmail.com> wrote in message
>> >> news:1104250803.810521.121410@.z14g2000cwz.googlegroups.com...
>> >> > How can I get the current job's name or job ID from a job step
>> > within
>> >> > the job in sql server?
>> >> >
>> >
>|||Tibor,
Thanks for quick reply. In my machine, I was getting invalid column
name JOBID and STEPID.
Tibor Karaszi wrote:
> tram,
> "Doesn't work" is not a very good problem description. I created a
job with one jobstep and added
> below SQL to the jobstep. Work just fine on my machine:
> SELECT 'The output file name is "' + output_file_name + '"'
> FROM msdb..sysjobsteps
> WHERE job_id = [JOBID]
> AND step_id = [STEPID]
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "tram" <tram_e@.hotmail.com> wrote in message
> news:1104323486.443287.4420@.z14g2000cwz.googlegroups.com...
> > Tibor,
> >
> > I appreciate your reply. I've seen the examples , but is not
working. I
> > was trying to know the JOB id of current job in the job step so
that I
> > can get the output file name from sysjobsteps.
> > Anyway, thanks for your reply.
> >
> >
> > Tibor Karaszi wrote:
> >> Did you check the samples at the web page that Jasper and me
posted?
> >>
> >> --
> >> Tibor Karaszi, SQL Server MVP
> >> http://www.karaszi.com/sqlserver/default.asp
> >> http://www.solidqualitylearning.com/
> >> http://www.sqlug.se/
> >>
> >>
> >> "tram" <tram_e@.hotmail.com> wrote in message
> >> news:1104265806.678523.298020@.z14g2000cwz.googlegroups.com...
> >> > Jasper,
> >> >
> >> > I've tried using token. But didn't work. Would you give an
example?
> >> >
> >> > Thanks
> >> >
> >> >
> >> >
> >> > Jasper Smith wrote:
> >> >> Use the [JOBID] job step token. See sp_add_job_step in BOL for
> >> > details. Also
> >> >> look at http://sqldev.net/sqlagent/SQLAgentStepTokens.htm
> >> >>
> >> >> --
> >> >> HTH
> >> >>
> >> >> Jasper Smith (SQL Server MVP)
> >> >> http://www.sqldbatips.com
> >> >> I support PASS - the definitive, global
> >> >> community for SQL Server professionals -
> >> >> http://www.sqlpass.org
> >> >>
> >> >> "tram" <tram_e@.hotmail.com> wrote in message
> >> >> news:1104250803.810521.121410@.z14g2000cwz.googlegroups.com...
> >> >> > How can I get the current job's name or job ID from a job
step
> >> > within
> >> >> > the job in sql server?
> >> >> >
> >> >
> >|||Thanks, Tibor. I've tried with sp_add_jobstep, it worked fine.
Initially I've just added it as transact sql command in the Enterprise
manager create job, step 1 and it did give an error.
tram wrote:
> Tibor,
> Thanks for quick reply. In my machine, I was getting invalid column
> name JOBID and STEPID.
> Tibor Karaszi wrote:
> > tram,
> >
> > "Doesn't work" is not a very good problem description. I created a
> job with one jobstep and added
> > below SQL to the jobstep. Work just fine on my machine:
> >
> > SELECT 'The output file name is "' + output_file_name + '"'
> > FROM msdb..sysjobsteps
> > WHERE job_id = [JOBID]
> > AND step_id = [STEPID]
> >
> > --
> > Tibor Karaszi, SQL Server MVP
> > http://www.karaszi.com/sqlserver/default.asp
> > http://www.solidqualitylearning.com/
> > http://www.sqlug.se/
> >
> >
> > "tram" <tram_e@.hotmail.com> wrote in message
> > news:1104323486.443287.4420@.z14g2000cwz.googlegroups.com...
> > > Tibor,
> > >
> > > I appreciate your reply. I've seen the examples , but is not
> working. I
> > > was trying to know the JOB id of current job in the job step so
> that I
> > > can get the output file name from sysjobsteps.
> > > Anyway, thanks for your reply.
> > >
> > >
> > > Tibor Karaszi wrote:
> > >> Did you check the samples at the web page that Jasper and me
> posted?
> > >>
> > >> --
> > >> Tibor Karaszi, SQL Server MVP
> > >> http://www.karaszi.com/sqlserver/default.asp
> > >> http://www.solidqualitylearning.com/
> > >> http://www.sqlug.se/
> > >>
> > >>
> > >> "tram" <tram_e@.hotmail.com> wrote in message
> > >> news:1104265806.678523.298020@.z14g2000cwz.googlegroups.com...
> > >> > Jasper,
> > >> >
> > >> > I've tried using token. But didn't work. Would you give an
> example?
> > >> >
> > >> > Thanks
> > >> >
> > >> >
> > >> >
> > >> > Jasper Smith wrote:
> > >> >> Use the [JOBID] job step token. See sp_add_job_step in BOL
for
> > >> > details. Also
> > >> >> look at http://sqldev.net/sqlagent/SQLAgentStepTokens.htm
> > >> >>
> > >> >> --
> > >> >> HTH
> > >> >>
> > >> >> Jasper Smith (SQL Server MVP)
> > >> >> http://www.sqldbatips.com
> > >> >> I support PASS - the definitive, global
> > >> >> community for SQL Server professionals -
> > >> >> http://www.sqlpass.org
> > >> >>
> > >> >> "tram" <tram_e@.hotmail.com> wrote in message
> > >> >> news:1104250803.810521.121410@.z14g2000cwz.googlegroups.com...
> > >> >> > How can I get the current job's name or job ID from a job
> step
> > >> > within
> > >> >> > the job in sql server?
> > >> >> >
> > >> >
> > >|||Yes, EM parses the SQL command and it doesn't recognize these tokens. Just ignore the warning from
EM and all is fine.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"tram" <tram_e@.hotmail.com> wrote in message
news:1104328701.411855.87570@.z14g2000cwz.googlegroups.com...
> Thanks, Tibor. I've tried with sp_add_jobstep, it worked fine.
> Initially I've just added it as transact sql command in the Enterprise
> manager create job, step 1 and it did give an error.
> tram wrote:
>> Tibor,
>> Thanks for quick reply. In my machine, I was getting invalid column
>> name JOBID and STEPID.
>> Tibor Karaszi wrote:
>> > tram,
>> >
>> > "Doesn't work" is not a very good problem description. I created a
>> job with one jobstep and added
>> > below SQL to the jobstep. Work just fine on my machine:
>> >
>> > SELECT 'The output file name is "' + output_file_name + '"'
>> > FROM msdb..sysjobsteps
>> > WHERE job_id = [JOBID]
>> > AND step_id = [STEPID]
>> >
>> > --
>> > Tibor Karaszi, SQL Server MVP
>> > http://www.karaszi.com/sqlserver/default.asp
>> > http://www.solidqualitylearning.com/
>> > http://www.sqlug.se/
>> >
>> >
>> > "tram" <tram_e@.hotmail.com> wrote in message
>> > news:1104323486.443287.4420@.z14g2000cwz.googlegroups.com...
>> > > Tibor,
>> > >
>> > > I appreciate your reply. I've seen the examples , but is not
>> working. I
>> > > was trying to know the JOB id of current job in the job step so
>> that I
>> > > can get the output file name from sysjobsteps.
>> > > Anyway, thanks for your reply.
>> > >
>> > >
>> > > Tibor Karaszi wrote:
>> > >> Did you check the samples at the web page that Jasper and me
>> posted?
>> > >>
>> > >> --
>> > >> Tibor Karaszi, SQL Server MVP
>> > >> http://www.karaszi.com/sqlserver/default.asp
>> > >> http://www.solidqualitylearning.com/
>> > >> http://www.sqlug.se/
>> > >>
>> > >>
>> > >> "tram" <tram_e@.hotmail.com> wrote in message
>> > >> news:1104265806.678523.298020@.z14g2000cwz.googlegroups.com...
>> > >> > Jasper,
>> > >> >
>> > >> > I've tried using token. But didn't work. Would you give an
>> example?
>> > >> >
>> > >> > Thanks
>> > >> >
>> > >> >
>> > >> >
>> > >> > Jasper Smith wrote:
>> > >> >> Use the [JOBID] job step token. See sp_add_job_step in BOL
> for
>> > >> > details. Also
>> > >> >> look at http://sqldev.net/sqlagent/SQLAgentStepTokens.htm
>> > >> >>
>> > >> >> --
>> > >> >> HTH
>> > >> >>
>> > >> >> Jasper Smith (SQL Server MVP)
>> > >> >> http://www.sqldbatips.com
>> > >> >> I support PASS - the definitive, global
>> > >> >> community for SQL Server professionals -
>> > >> >> http://www.sqlpass.org
>> > >> >>
>> > >> >> "tram" <tram_e@.hotmail.com> wrote in message
>> > >> >> news:1104250803.810521.121410@.z14g2000cwz.googlegroups.com...
>> > >> >> > How can I get the current job's name or job ID from a job
>> step
>> > >> > within
>> > >> >> > the job in sql server?
>> > >> >> >
>> > >> >
>> > >
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment