Sql Server Experts,
I need some help on getting the job information from view sysjobs using job_id
I get the job_id from the output of sp_who2 command by saving the result in a table.
insert into #sp_who execute sp_who2
The column value ProgramName in this table is something like this:
SQLAgent - TSQL JobStep (Job 0x9C0B12A43932864CA7C6B9F3ED00BD8A : Step 1)
SQLAgent - TSQL JobStep (Job 0x9C0B12A43932864CA7C6B9F3ED00BD8A : Step 1)
SQLAgent - TSQL JobStep (Job 0x9C0B12A43932864CA7C6B9F3ED00BD8A : Step 1)
SQLAgent - TSQL JobStep (Job 0x9C0B12A43932864CA7C6B9F3ED00BD8A : Step 1)
SQLAgent - TSQL JobStep (Job 0x9C0B12A43932864CA7C6B9F3ED00BD8A : Step 1)
SQLAgent - TSQL JobStep (Job 0x9C0B12A43932864CA7C6B9F3ED00BD8A : Step 1)
That's where I get the job_id, but it is in string format.
I'm able to query the job view with the below:
select * from msdb.dbo.sysjobs where job_id=0x9C0B12A43932864CA7C6B9F3ED00BD8A
My question is, how do I do this in a script instead of hard coding the job_id?
I need to read each row of #sp_who table and get the job name from msdb.dbo.sysjobs.
I have tried a few things, but always got convert errors.
Thanks in advance.
Pingx
pingx