jeudi 10 août 2017

Teradata - if... then... depending on day of week (run different code)

Background: I'm building a rather simple table that is simply a select * from another table that needs to select the last 3 day's worth of data if it is a Monday and the last one day's worth of data if it's Tuesday-Friday.

Problem: I'm not sure I understand how to do this using an IF... THEN statement.

Code attempted:

IF DAY_OF_WEEK = 2

    THEN

         SELECT * FROM TABLE WHERE DATE BETWEEN CURRENT_DATE-3 AND CURRENT_DATE

    ELSE 

         SELECT * FROM TABLE WHERE DATE BETWEEN CURRENT_DATE-1 AND CURRENT_DATE

    END IF

Aucun commentaire:

Enregistrer un commentaire