Friday, February 24, 2012

How can I get the current job's name or job ID from a job step within the job

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:[vbcol=seagreen]
> 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...
within[vbcol=seagreen]|||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:[vbcol=seagreen]
> 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...
within[vbcol=seagreen]|||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:
> within
>|||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[vbcol=seagreen]
> 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...
within[vbcol=seagreen]|||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:
> details. Also
> within
>|||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:[vbcol=seagreen]
> 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...|||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:
>

No comments:

Post a Comment