Skip to content
Advertisement

SQL Month YTD and prior YTD data

I am trying to write a query to return Month-To-Date data for the Current Year, and also the Previous Year.
Meaning I need data from 2017-07-01 to 2017-07-26 and also 2016-07-01 to 2016-07-26.

However, my query currently returns data from 2017-07-01 to 2017-07-26 (correctly) but also returns data from 2016-07-01 to 2016-07-31 (incorrectly).

How can I have the data for the same time period (MTD) from two different years?

The table includes date, day in quarter, year, quarter, month and week but no day column…

Advertisement

Answer

I would go like this:

When you want to refer to MTD of NOW() You can use:

I deleteted date from the query in order enable the grouping by month and year.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement