USE msdb;
GO

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

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

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

-- Find weekly/monthly jobs
SELECT JobName, Frequency, ScheduledStartTime
FROM DevlDUTASJobSchedule.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) = 'DEVL_MONTHLY_DTSCHGVR';
SELECT JobName, PredecessorJobName
FROM DevlDUTASJobSchedule.dbo.JobDependencies
WHERE JobName = @Job;
GO

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