|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Wednesday, June 12, 2013 6:00 AM
Points: 47,
Visits: 147
|
|
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
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Today @ 4:59 PM
Points: 386,
Visits: 1,425
|
|
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 JOIN msdb..sysjobs j ON jh.job_id = j.job_id WHERE jh.step_id = 0
The SQL Guy @ blogspot
About Me
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Wednesday, June 12, 2013 6:00 AM
Points: 47,
Visits: 147
|
|
| That looks good - many thanks!
|
|
|
|