I have a SQL Server query that I plan on using to feed data into some dashboards. The last thing I need to do now is automate the dates in the query so that I'm only pulling the data I need. I have a dimension_date table table which has fields like DateSeq, WorkingDayOfMonth and TotalWorkingDaysOfMonth among other fields.
Pretty much, I want the query to be able to do this:
IF Current Dates' WorkingDayOfMonth = 1 THEN SELECT DateSeq >= First Day Of Prior Month AND DateSeq <= Last Day of Prior Month ELSE SELECT DateSeq >= First day of Current Month AND DateSeq < Current Date
In other words, if the current date is the first working day of the month, I want the dashboard to populate with data from last month, else the dashboard should populate with data from this month, less the current day.