0

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.

  • 1
    which database version are you using? Use combinations of the DateAdd function in your where clause. Here are some examples: https://stackoverflow.com/questions/11743810/how-to-get-first-and-last-day-of-previous-month-with-timestamp-in-sql-server. – Johnny Fitz Jan 22 '21 at 23:32
  • Please provide sample data and desired results. – Gordon Linoff Jan 22 '21 at 23:50

0 Answers0