query that looks back 12 weeks

metropia
metropia used Ask the Experts™
on
In my query, I need to look at the last 12 week ending dates, or 12 months in the where clause. Could anyone help me out adding this clause?

My query:

select week_ending as 'Week Ending', 
          convert(decimal(10,2),
          avg(roll_change_time)) as 'Average Roll Change Time' 
from roll_change_data
group by week_ending

Open in new window



Thank you much.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
to get last 12 months

WHERE yourdatefield > DATEADD(m, -12, current_timestamp);

Author

Commented:
thank you, and how to get the last 12 weeks?
Commented:
WHERE yourdatefield > DATEADD(ww, -12, current_timestamp);

Author

Commented:
thank you guys!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial