mercredi 1 septembre 2021

SQL if statement for date range

Hi I was needing help with the syntax to add a condition where the current date is retrieved if today is after the 5th of each month but if its between the 1st to the 5th then it should retrieve the month before this month. Is it something you can help with please? Below is how my query is structured.

 Select * 
 FROM table1  
  left join  table2
       on e.ENTITY_NBR  = d.entity_nbr
     and cast(getdate() as date) between MONTH_BEGIN_DATE and MONTH_END_DATE

Aucun commentaire:

Enregistrer un commentaire