How to search records until the previous month?

Asked

Viewed 23 times

-1

I need to get all the data, from the beginning to the previous month, this query has to be dynamic, I can not put a fixed date, because next month we need to consult again...

In summary, today I need to get all the data until the day 28/02/2021 and next month until the day 31/03/2021 and so on.

1 answer

0


    ... where DATEPART(m, _DATA_ ) = DATEPART(m, DATEADD(m, -1, getdate())) 
                 

Extract the month of the date

DATEPART(m, DATE )

and compares by decreasing one month from the current date

DATEPART(m, DATEADD(m, -1, getdate()))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.