October 16, 2012 at 6:52 am
Hi all,
Is there a way I could output the username of whoever invoked a SQL job each time it runs? ...and perhaps write it to a table?
I have used suser_name() to output the user that runs each step, but these are all being automatically started by the SQL Agent service account, so obviously that username is all I get.
Any ideas?
Thanks,
Matt
October 17, 2012 at 5:30 am
You can find this in the job history table.
SELECT j.name,
jh.run_date,
jh.run_time,
SUBSTRING(jh.message, CHARINDEX('.', jh.message) + 3, CHARINDEX('.', jh.message, CHARINDEX('.', jh.message) + 1) - CHARINDEX('.', jh.message) - 3) AS MiddleMessage
FROM msdb..sysjobhistory jh
JOINmsdb..sysjobs j
ON jh.job_id = j.job_id
WHEREjh.step_id = 0
October 17, 2012 at 6:45 am
That looks good - many thanks!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply