SQLServerCentral.com / SQL Server 2012 / SQL Server 2012 - T-SQL / Need TSQL help to monitor the scheduled jobs in SQL 2012 / Latest PostsInstantForum.NET v99.99.99SQLServerCentral.comhttp://www.sqlservercentral.com/Forums/notifications@sqlservercentral.comFri, 09 Dec 2016 09:24:36 GMT20RE: Need TSQL help to monitor the scheduled jobs in SQL 2012http://www.sqlservercentral.com/Forums/Topic1502536-3077-1.aspxI'm going to take a quick stab at this since nobody has responded yet. What I am showing you here is not a complete solution but should get you moving in the right direction. First, msdb.dbo.sp_help_jobactivity should give you a number of columns: the query below runs fine for me on 2008 and 2012. [code="sql"]DECLARE @job_hist TABLE ( session_id int, job_id varchar(100), job_name varchar(200), run_requested_date datetime, run_requested_source int, queued_date datetime, start_execution_date datetime, last_executed_step_id int, last_executed_step_date datetime, stop_execution_date datetime, next_scheduled_run_date datetime, job_history_id bigint, [message] varchar(1000), run_status int, operator_id_emailed int, operator_id_netsent int, operator_id_paged int)INSERT @job_hist EXEC msdb.dbo.sp_help_jobactivitySELECT 'Scheduled' AS Scheduled_or_manual, PATINDEX('%The Job was invoked by Schedule%',[message]), * FROM @job_histWHERE PATINDEX('%The Job was invoked by Schedule%',[message])&lt;&gt;0UNION ALLSELECT 'Manual', PATINDEX('%The Job was invoked by user%',[message]), * FROM @job_histWHERE PATINDEX('%The Job was invoked by user%',[message])&lt;&gt;0[/code]That said, you can also get this information from msdb..sysjobhistory[code="sql"]SELECT 'manual' AS Scheduled_or_manual, * FROM msdb..sysjobhistoryWHERE step_id=0AND PATINDEX('%The Job was invoked by user%',[message])&lt;&gt;0UNION SELECT 'scheduled' AS Scheduled_or_manual, * FROM msdb..sysjobhistoryWHERE step_id=0AND PATINDEX('%The Job was invoked by schedule%',[message])&lt;&gt;0[/code]AGAIN: Both the above queries are not complete solutions but should get you started.Tue, 08 Oct 2013 13:37:02 GMTAlan.BNeed TSQL help to monitor the scheduled jobs in SQL 2012http://www.sqlservercentral.com/Forums/Topic1502536-3077-1.aspxI have a request to monitor couple of scheduled SQL jobs in 2012 version.Example: There is a SQL job which is scheduled 6 times a day starting 12:55 AM PST. Now for what ever reason, if this job fails or if it is an out of cycle run. Because, we have few scenarios where we need to manually kick off the jobs apart from schedule. I need to differentiate between manually kicked off runs and Scheduled runs of that job.I checked EXEC msdb.dbo.sp_help_jobactivity but is only giving me requested date and starttime info.I need prepare a script to dynamically check and differentiate between manually kicked off runs and Scheduled runs of SQL jobs.Tue, 08 Oct 2013 04:28:16 GMTMac1986