Selecting for previous month (December 2022) in January 2023
Hello!
I'm new to the system I'm working on, and I have a part of a statement that needs to grab the previous month.
....and MONTH(TX3.date_of_service)= MONTH(dateadd(mm,-1,GETDATE()))
However, when it hits January, I'm left with month 0.
Does anyone know a workaround to grab December of the previous year, while still functioning normally for the rest of the current year.
Thank you!
Comments
Are you sure that's where your problem is? If I do:
select MONTH(dateadd(mm,-1,GETDATE()))
I get 12. If I create a query with a where clause similar to yours on my data, it works as expected.
You're correct! I guess I'm back to square one. The query runs inside of the NetSmart Avatar system and pulls no data for December. hmmm
The problem is in the line above, I believe:
and (YEAR(TX3.date_of_service)= YEAR(GetDate()))
and MONTH(TX3.date_of_service)= MONTH(dateadd(mm,-1,GETDATE()))
Never mind. I figured it out. Thank you!