So I have this existing case statement in my query:
SELECT CASE WHEN dl.list_id = 1000000 AND dl.date_inserted != '' THEN dl.date_inserted ELSE dl.entry_date END AS date
Let me give some context here. So as soon as we have a record move to list_id 1000000 I need to reference date_inserted to determine when this record entered the table but for all else I need to reference entry_date. Next I need to be able to identify which day of the week the above date amounts to for ex. Saturday. So I created a 2nd table which lists each date for 2020 and the corresponding day so my plan is
CASE WHEN mc1.day IS NOT NULL THEN mc1.day ELSE mc2.day END AS day_of_the_week LEFT JOIN "db"."meta_calendar" mc1 ON dl.date_inserted = mc1.date LEFT JOIN "db"."meta_calendar" mc2 ON dl.entry_date = mc1.date AND dl.date_inserted = ''
The result seems to be producing the expected output but I have a feeling there could be a better way to achieve this. Basically I need this validated and if this is not the ideal way to achieve this then please advise