Skip to content
Advertisement

Select all completed months until certain date in SQL Server

I have a query that returns certain time series information. But since I am doing analysis for each completed month, I would like to ignore the last month information so it does not contaminate the data. So the actual data would look similar to this:

So, I was thinking in doing something like:

where T.Date <= Datefromparts(Year(max(T.Date)),Month(Max(T.Date)),1)

And I would receive something like:

But seems like this is not the way.

Advertisement

Answer

I see nothing wrong with your approach:

Perhaps more colloquially, this could be written as:

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