I'd like to collect data for a report that goes back three months using the datepart function and month as my interval. As an example if I wrote a query the following way:
between datepart(mm, getdate()) -3 and datpart(mm, getdate())
I would get the dataset I'm looking for, however; come January 2010 when the query runs
between datepart(mm, '01/01/2010') -3 and datpart(mm, '01/01/2010')
the datepart interval is going to return a negative integer
ie, select datepart(mm, '01/01/2010') -1 returns the value: -1
using the datepart(mm, getdate()) function, is there a way to go back and retrieve months from previous years?
Thank you in advance.