Hi @brenda grossnickle ,
Welcome to Microsoft Q&A!
Please refer below query and check whether it is working.
;with cte as (
SELECT *,COUNT(CASE category WHEN 'Start' THEN 1 END) OVER (PARTITION BY process_name ORDER BY recid) AS Grp
FROM cs_process_log
WHERE category IN ('Start','End'))
,cte1 as (
SELECT process_name,run_datetime, category,
MAX(CASE category WHEN 'Start' THEN run_datetime END) over (partition by process_name,Grp) AS run_datetime_start,
MAX(CASE category WHEN 'End' THEN run_datetime END) over (partition by process_name,Grp) AS run_datetime_end
FROM cte
union
SELECT process_name,run_datetime,category,run_datetime,NULL
from cs_process_log
where category not IN ('Start','End'))
select distinct DATEDIFF(MINUTE,run_datetime_start,run_datetime_end) MINUTES_RUN,
process_name,category,run_datetime_start,run_datetime_end from cte1
where category<>'end'
order by run_datetime_start desc
Output:
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.