Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Last 14 weeks of year

Author  Topic 

Jaykays
Starting Member

2 Posts

Posted - 2008-04-28 : 14:59:45
hey all
i am trying to get a filter in a report that return the last 14 complete weeks. so sunday through to Monday but only display this week once it's comlete next week. i have this
FTDW.dbo.day.sql_date < dateadd(w,-1,getdate()) and FTDW.dbo.day.sql_date > dateadd(w,-15,getdate())
but i get incomplete week 3 and last week. any ideas?

bfoster
Starting Member

30 Posts

Posted - 2008-04-28 : 15:29:31
First, "w" is weekday, and since you are talking about weeks, I assume you meant to use "ww", "wk", or "week".

http://msdn2.microsoft.com/en-us/library/ms186819.aspx

I'm thinking something like this may work although maybe there is an easier way. You may need to tweak it a bit depending on if you have timestamps other than 00:00 or not.

FTDW.dbo.day.sql_date < dateadd(day, (datepart(weekday, getdate()) - 1) * -1, getdate()) and FTDW.dbo.day.sql_date > dateadd(week, -14, dateadd(day, (datepart(weekday, getdate())) * -1, getdate()))
Go to Top of Page

Jaykays
Starting Member

2 Posts

Posted - 2008-04-28 : 15:39:10
this is great thank you sir. oen more thing is there a way to exclude the current week?
Go to Top of Page
   

- Advertisement -