added files from swmgmt03

This commit is contained in:
Schork Thierry (Galenica - ADM)
2025-09-22 09:00:00 +02:00
parent de97031b1e
commit 63d058a7eb
67 changed files with 13300 additions and 1 deletions

View File

@@ -0,0 +1,28 @@
DECLARE @tpl VARCHAR(255)='exec [msdb].[dbo].[sp_start_job] @job_name= ''@job@''; '+CHAR(13)+CHAR(10)
DECLARE @q VARCHAR(MAX)='';
WITH cteActivity AS (
SELECT job_id, session_id, ROW_NUMBER()OVER(PARTITION BY job_id ORDER BY start_execution_date DESC) AS rnk
FROM msdb.dbo.sysjobactivity
)
SELECT @q = @q + REPLACE(@tpl, '@job@', j.name)
FROM msdb.dbo.sysjobs j
WHERE name LIKE 'ActivePosTran distribution agent -%'
AND NOT EXISTS(
--the job is currently running
SELECT 1
FROM msdb.dbo.sysjobactivity sja
JOIN cteActivity ca ON ca.job_id = sja.job_id AND ca.session_id = sja.session_id
WHERE sja.job_id = j.job_id
AND ca.rnk=1
AND sja.start_execution_date IS NOT NULL
AND sja.stop_execution_date IS NULL
)
IF NULLIF(@q,'') IS NOT NULL
BEGIN
PRINT @q
select @q
EXEC(@q)
END