July 15, 2012 at 1:49 pm
I want to see all jobs with job owner in a server. How can i script it out with using t-sql command?
Thank you in advance 🙂
July 15, 2012 at 2:03 pm
selectname AS JobName
, SUSER_SNAME(owner_sid) AS JobOwner
from msdb.dbo.sysjobs
or you could join msdb.dbo.sysjobs to master.sys.server_principals like so
SELECTj.name AS JobName
, sp.name AS JobOwner
FROM msdb.dbo.sysjobs j INNER JOIN
master.sys.server_principals sp ON j.owner_sid = sp.principal_id
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs" 😉
July 15, 2012 at 4:39 pm
July 15, 2012 at 7:05 pm
It's working Thank you 🙂
July 16, 2012 at 11:08 am
Perry Whittle (7/15/2012)
or you could join msdb.dbo.sysjobs to master.sys.server_principals like so
SELECTj.name AS JobName
, sp.name AS JobOwner
FROM msdb.dbo.sysjobs j INNER JOIN
master.sys.server_principals sp ON j.owner_sid = sp.principal_id
Be careful. Jobs owned by logins that enter the instance via a Windows Group will not be returned by the above query.
The first query supplied is the safer one to use:
SELECT name AS JobName,
SUSER_SNAME(owner_sid) AS JobOwner
FROM msdb.dbo.sysjobs
ORDER BY JobName;
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply