Only Teradata SQL is available for use.
I’m trying to dynamically create a list of dates on which give jobs will run. Here is a simplified version of what I’m dealing with.
Calendar (covers 2012+)
--------
Calender Date
Business Day Flag - 1 = This is a Business Day, 0 = Weekend
Holiday Flag - 1 = This is a Holiday, 0 = Non-Holiday
Year
Month
Day
Schedule (several more fields available, but not relevant)
--------
Day Type - Business Day or Calendar Date
Day Number - Represents either a Business or Calendar Day
Eligible to run on holiday - Yes / No
Logic done through a case statement in the select
when d.day_type = 'BD' and day_num = c.business_day_of_month then 'Y'
when d.day_type = 'CD' and day_num = c.day_of_month then 'Y'
else 'N' as run_flag
However, when the run_flag = ‘Y’ and the Holiday_Flag = 1 then the job should be listed to run on the next Business/Calendar day (depending on the day_type).
I think I need to use a lead/lag but I don’t know if I can get it to run through the logic involved.
Any ideas?
Try this: