USE DevlDUTASJobSchedule;
GO

DECLARE @Runday DATE = DATEADD(day, +0, CAST(GETDATE() AS DATE)); -- -1 for Yesterday

SELECT 
    jeh.ExecutionID,
    jeh.JobName,
    jeh.RunDate,
    jc.ScheduledStartTime,
    jeh.ActualStartTime,
    jeh.ActualEndTime,
    jeh.Status,
    jeh.ErrorMessage,
    jeh.OverrideFlag,
    jeh.OverrideBy
FROM dbo.JobExecutionHistory jeh
INNER JOIN dbo.JobControl jc 
    ON jeh.JobName = jc.JobName
WHERE jeh.RunDate = @Runday
ORDER BY jc.ScheduledStartTime, jeh.ActualStartTime;
