"sql find longest running job step" Code Answer's

You're definitely familiar with the best coding language SQL that developers use to develop their projects and they get all their queries like "sql find longest running job step" answered properly. Developers are finding an appropriate answer about sql find longest running job step related to the SQL coding language. By visiting this online portal developers get answers concerning SQL codes question like sql find longest running job step. Enter your desired code related query in the search bar and get every piece of information about SQL code related question on sql find longest running job step. 

sql find longest running job step

By Exuberant ElandExuberant Eland on May 21, 2021
/*============================================= 
  Variables: 
    @MinHistExecutions - Minimum number of job step executions we want to consider 
    @MinAvgSecsDuration - Threshold for minimum job step duration we care to monitor 
    @HistoryStartDate - Start date for historical average 
    @HistoryEndDate - End date for historical average 
  
  These variables allow for us to control a couple of factors. First 
  we can focus on job steps that are running long enough on average for 
  us to be concerned with (say, 30 seconds or more). Second, we can 
  avoid being alerted by job steps that have run so few times that the 
  average and standard deviations are not quite stable yet. This script 
  leaves these variables at 1.0, but I would advise you alter them 
  upwards after testing. 
  
  Returns: One result set containing a list of job steps that 
  are currently running and are running longer than two standard deviations 
  away from their historical average. The "Min Threshold" column 
  represents the average plus two standard deviations. 
  
  note [1] - comment this line and note [2] line if you want to report on all history for job steps 
  note [2] - comment just this line is you want to report on running and non-running job steps 
 =============================================*/ 
  
DECLARE   @HistoryStartDate datetime 
  ,@HistoryEndDate datetime  
  ,@MinHistExecutions int   
  ,@MinAvgSecsDuration int  
  
SET @HistoryStartDate = '19000101' 
SET @HistoryEndDate = GETDATE() 
SET @MinHistExecutions = 1.0 
SET @MinAvgSecsDuration = 1.0 
  
DECLARE @currently_running_jobs TABLE ( 
    job_id UNIQUEIDENTIFIER NOT NULL 
    ,last_run_date INT NOT NULL 
    ,last_run_time INT NOT NULL 
    ,next_run_date INT NOT NULL 
    ,next_run_time INT NOT NULL 
    ,next_run_schedule_id INT NOT NULL 
    ,requested_to_run INT NOT NULL 
    ,request_source INT NOT NULL 
    ,request_source_id SYSNAME NULL 
    ,running INT NOT NULL 
    ,current_step INT NOT NULL 
    ,current_retry_attempt INT NOT NULL 
    ,job_state INT NOT NULL 
    ) 
  
--capture details on jobs 
INSERT INTO @currently_running_jobs 
EXECUTE master.dbo.xp_sqlagent_enum_jobs 1,'' 
  
;WITH JobStepsHistData AS 
( 
  SELECT job_id, step_id 
,date_executed=msdb.dbo.agent_datetime(run_date, run_time) 
,secs_duration=run_duration/10000*3600 
                      +run_duration%10000/100*60 
                      +run_duration%100 
  FROM msdb.dbo.sysjobhistory 
  WHERE run_status = 1 -- Succeeded 
) 
,JobHistStats AS 
( 
  SELECT job_id, step_id 
        ,AvgDuration = AVG(secs_duration*1.) 
        ,AvgPlus2StDev = AVG(secs_duration*1.) + 2*stdevp(secs_duration) 
  FROM JobStepsHistData 
  WHERE date_executed >= DATEADD(day, DATEDIFF(day,'19000101',@HistoryStartDate),'19000101') 
  AND date_executed < DATEADD(day, 1 + DATEDIFF(day,'19000101',@HistoryEndDate),'19000101')   
  GROUP BY job_id, step_id 
  HAVING COUNT(*) >= @MinHistExecutions 
  AND AVG(secs_duration*1.) >= @MinAvgSecsDuration 
) 
-- need to select from the CTE's, and join to msdb for final result 
SELECT jd.job_id 
      ,j.name AS [JobName] 
      ,sjs.step_id 
    ,sjs.step_name 
      ,MAX(act.start_execution_date) AS [ExecutionDate] 
      ,AvgDuration AS [Historical Avg Duration (secs)] 
      ,AvgPlus2StDev AS [Min Threshhold (secs)] 
FROM JobStepsHistData jd 
JOIN JobHistStats jhs on jd.job_id = jhs.job_id AND jd.step_id = jhs.step_id 
JOIN msdb..sysjobs j on jd.job_id = j.job_id 
JOIN msdb..sysjobsteps sjs on jd.job_id = sjs.job_id AND jd.step_id = sjs.step_id 
JOIN @currently_running_jobs crj ON crj.job_id = jd.job_id --see note [1] above 
JOIN msdb..sysjobactivity AS act ON act.job_id = jd.job_id 
AND act.stop_execution_date IS NULL 
AND act.start_execution_date IS NOT NULL 
WHERE DATEDIFF(SS, act.start_execution_date, GETDATE()) > AvgPlus2StDev 
AND crj.job_state = 1 --see note [2] above 
GROUP BY jd.job_id, j.name, sjs.step_id, sjs.step_name, AvgDuration, AvgPlus2StDev

Source: www.mssqltips.com

Add Comment

0

All those coders who are working on the SQL based application and are stuck on sql find longest running job step can get a collection of related answers to their query. Programmers need to enter their query on sql find longest running job step related to SQL code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about sql find longest running job step for the programmers working on SQL code while coding their module. Coders are also allowed to rectify already present answers of sql find longest running job step while working on the SQL language code. Developers can add up suggestions if they deem fit any other answer relating to "sql find longest running job step". Visit this developer's friendly online web community, CodeProZone, and get your queries like sql find longest running job step resolved professionally and stay updated to the latest SQL updates. 

SQL answers related to "sql find longest running job step"

View All SQL queries

SQL queries related to "sql find longest running job step"

sql find longest running job step mysql get longest string in column oracle start job Port 5432 is already in use Usually this means that there is already a PostgreSQL server running on your Mac. If you want to run multiple servers simultaneously, use different ports. oracle running queries oracle show running procedures oracle show running queries Error Code: 1290. The MySQL server is running with the --secure-file-priv option so it cannot execute this statement copy running config startup config could not find driver (SQL: select * from information_schema.tables where table_schema = pics and table_name = migrations and table_type = 'BASE TABLE') illuminate database queryexception could not find driver (sql select * from sql find second highest salary employee how to find average value in sql sql query to find percentage of null values in a table sql find leading space find below average salary in sql how to find total working hour in sql Find most frequent value in SQL column FIND DUPLICATES IN COLUMN SQL how to find median of a column sql find a even number sql how to find employee names starts with in sql how to find second highest salary in sql sql alter column name sql server https://www.jitendrazaa.com/blog/sql/sqlserver/export-documents-saved-as-blob-binary-from-sql-server/ find a column in all tables postgres Did not find any relation named postgres how to find the top 2 unique records using mysql mysql find missing values mysql installer did not find packages in the current bundle suitable for installation mysql find the row ites of the hoghest value at on column tsql find the value and count of the item that occurs the most in a column find text in stored procedure sql update query get database list in sql server sql concat string with column value sql server get users oracle sql drop index sql insert inserted id sql server cast date dd/mm/yyyy pl/sql procedure example sql declare variable sql convert datetime to year month delete table sql sql server update c# example code key validation sql pl sql trigger determine if insert or update or delete finding duplicate column values in table with sql add column table sql default value get column name sql server sql query with replace function declare table variable sql server rename table sql server sql server add unique constraint get current month last date in sql server sql server alter column base64 encode sql server sql count duplicate rows SQL Integer devision convert utc to est sql sql server drop table if exists truncate delete and drop in sql oracle sql create user sql date format yyyy-mm-dd sql server to_date sql server to date sql convert string to date yyyymmdd sql convert string to date yyyymmddhhmmss sql print all names that start with a given letter sql server beginning of month copy table sql server t-sql disable system versioning sql query to get the number of rows in a table sql server 2016 split string sql select except null create table if not exists sql sql server concat string and int sql show tables how to use group_concat in sql server sql count mysql run sql file sql substring sql oracle update multiple rows how to create table in sql sql syntax create timestamp column sql insert from excel sql where contains how to sort names in alphabetical order in sql id increment ms sql server sql to char function with date SQL: merging multiple row data in string How to View column names of a table in SQL sql update from select sql drop column sql datetime now get duplicate records in sql with in sql server sql server restore database add multiple field in table sql SQL DELETE download sql server for mac sql timestamp to date import sql file from laravel create user defined table type in sql date datatype in sql DB: in eloquent using sql order of sql sql delete column case when switch in SQL get tables in database sql replace null with 0 in sql remove default constraint sql server ms sql now update a row in sql in sql orcale sql change column type sql multiple insert postgres insert in to table sql sql server pivot rows to columns how to connect to xampp sql server on windows cmd t-sql update from select sql join on a subquery sql like case sensitive sql select execute table valued function in sql sql get last ID oracle sql copy table without data max in sql sql server today minus n data types in sql sql in buscar nombre de columna en todas las tablas sql server sql if empty then sql as w3schools sql foreign key how to set foreign key in sql server sql primary key how to write uppercase in sql how to get initials in sql sql counter column import sql file mysql commadn line how to export table data from mysql table in sql format sql server time stamp procedures in pl sql microsoft sql server how to prevent application from sql injection in codeigniter like operator in sql unique element in sql left joing sql what is delete in sql how to update data in sql year sql server function get week day from date in sql sql is not null alter column sql server sql how to partition rank sql select inner join example sql describe count function in sql add multiple columns to table sql aliases in sql if in sql how to copy one table to other one in sql return columns from table sql sql delete duplicate rows but keep one sql server select rows by distinct column alter in sql sql limit order by describe table in sql join types in sql view t-sql mail configuration sql check same row sql where contains part of string oracle SQL developer UPDATE command in SQL get first monday of month sql sql like How to Add a Default Value to a Column in MS SQL Server mode in sql sql how to get courses that i have made prerequisites apt install sql server store unicode characters in sql varchar() fields sql server version control do you know sql like syntax in sql sql script to get a type task on jira datbase for 12 months how to get specific salary in sql How do I install microsoft SQL on my Mac? local vs global variables in sql t sql dynamic top n query sql table intermédiaire an exception occurred while executing a transact-sql statement or batch user,group or role already is not in sql server load utilities in sql server SQL print multiple variable oracle sql for each row create new databse sql automatically update database last seen datetime in sql

Browse Other Code Languages

CodeProZone