I am making a line chart that shows yearly sales from the past 5 years. I want to pull all the orders in our database that are from those years. For example, since it is 2024 right now, I want it to pull all orders from 2020, 2021, 2022, 2023, and all orders so far in 2024. I also would like this to update automatically when it becomes 2025. I don’t want it to show me a complete 5 years worth of data since that will also show me some of 2019’s data. How do I pull all data that has a date with one of those past 5 year numbers?
What I’ve found so far is WHERE statements that use getdate(year, -5, today()) or getdate(day, -1826, today()) but these both will give me 2019’s data as well since todays date is 8/12/2024 and 5 years ago exactly is 8/12/2019.
I hope this all makes sense. Let me know if I could explain something better
Dustin Yoder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.