Re: Question: How to query for past months regardless of date
Posted in 1998
Douglas Wilson wrote: > > bstaib wrote: > > > > I am trying to formulate a SQL query to retreive rows by comparing two > > DATE columns. The end result is to compare score values from a month in > > the current year to a month in the previous year. While year and month > > are obviously easy to identify, the particular day value may vary from > > year to year (the last fiscal day of the month for Aug of 1997 may have > > been the 27th and in 1996 it may have been the 30th). > > > > "where date_column = current - 1 units year" > > try: where month(date_column)=month(current) > and year(date_column)=year(current)-1 > > or: where extend(date_column units year to month)= > extend(current units year to month)-interval (1) year to year > > both untested, the second is better, but neither > will use any index and so may be slow. > > Good Luck, > Douglas Wilson Thanks, I'm utilizing the first option and it works great.