I am trying to extract all event end dates for events that expire in 2 working days. So for Friday and Thursday I want dates that end in 4 days or less, for Saturday dates that end in 3 days, for Sun-Wed dates that end within 2 days and +3 for all public holidays which are listed in column dateval in tempdate.
The script below isn't working, it only extact dates for +2 days. I understand I need to use a case statement, but am really not understanding how to implement that. Does someone have any ideas?
select event_end_date
from mdmins.table
/*separating by date to find expiring dates*/
where ( (dayofweek(c.event_end_date) in (5,6) /*Friday & Thursday*/
and date(c.event_end_date) < current_date + 4 days
and date(c.event_end_date) >= current_date)
or (dayofweek(c.event_end_date) in (1,2,3,4) /*All other days of week*/
and date(c.event_end_date) < current_date + 2 days
and date(c.event_end_date) >= current_date)
or (dayofweek(c.event_end_date) = 7 /*Saturday - not that this should be needed, but just in case*/
and date(c.event_end_date) < current_date + 3 days
and date(c.event_end_date) >= current_date)
or (date(c.event_end_date) < (select dateval from mdmins.tempdate where dateval = (current date + 3 days)) /*a holiday is on in 3 days, so 2 working days before*/
and date(c.event_end_date) >= current_date) )
CASEstatement (which is an actual thing), and you don't need one. Do you have an outright Calendar file with aworkingDayBoolean column? That would make this far easier to write. Calendar files are, hands down, one of the most useful analysis tables possible. Barring that, creating a temp/virtual table via CTE andVALUES(...)would greatly simplify this. - Clockwork-Muse