SQLTeam.com | Weblogs | Forums

Finding 1 week Prior

sql2008

#1

I am using this where clause in my query below. This gives me a week of data. How do I get the prior week of data. example I want to pull 3/28 through 4/1.

(YEAR([clm_rcvd]) = YEAR(GETDATE())) AND (DATEPART(wk, [clm_rcvd]) = DATEPART(wk, GETDATE())))


#2

basically, replace GETDATE() with
DATEADD(week, -1, GETDATE())


#3

Maybe I'm overthinking or just plain misunderstood the question, but here's an alternative:

select ...
  from ...
 where clm_rcvd>=dateadd(week,datediff(week,@@datefirst,current_timestamp)-1,@@datefirst-1)
   and clm_rcvd<dateadd(week,datediff(week,@@datefirst,current_timestamp)-1,@@datefirst+6)
;