USE msdb;
GO

PRINT '================================================================================';
PRINT 'SECTION 1: JOB CONTROL INFORMATION';
PRINT '================================================================================';
GO

-- View all active jobs
SELECT JobName, ScheduledStartTime, Frequency, IsActive
FROM ProdDUTASJobSchedule.dbo.JobControl
WHERE IsActive = 1
ORDER BY Frequency, ScheduledStartTime;
GO

-- View all inactive jobs
SELECT JobName, Frequency, ScheduledStartTime
FROM ProdDUTASJobSchedule.dbo.JobControl
WHERE IsActive = 0
ORDER BY Frequency;
GO

-- Find weekly/monthly jobs
SELECT JobName, Frequency, ScheduledStartTime
FROM ProdDUTASJobSchedule.dbo.JobControl
WHERE Frequency IN ('WEEKLY', 'MONTHLY')
ORDER BY Frequency, ScheduledStartTime;
GO

PRINT '================================================================================';
PRINT 'SECTION 2: JOB DEPENDENCIES';
PRINT '================================================================================';
GO

-- Check dependencies for a job
DECLARE @Job NVARCHAR(100) = 'PROD_MONTHLY_DTSCHGVR';
SELECT JobName, PredecessorJobName
FROM ProdDUTASJobSchedule.dbo.JobDependencies
WHERE JobName = @Job;
GO

-- Show dependency chain overview
SELECT d.JobName, d.PredecessorJobName, jc.ScheduledStartTime, jc.Frequency
FROM ProdDUTASJobSchedule.dbo.JobDependencies d
JOIN ProdDUTASJobSchedule.dbo.JobControl jc ON d.JobName = jc.JobName
ORDER BY jc.Frequency, jc.ScheduledStartTime;
GO
