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 2008 Forums
 Transact-SQL (2008)
 How to build 7 day slots based on start and end da

Author  Topic 

atlzbest
Starting Member

7 Posts

Posted - 2010-04-08 : 20:12:21
Hi All,

I have a interesting challenge. I have data lets say RowID, UserID, Date in a table. If UserID appears twice within a 7 day period, i need to delete the one with the lower RowID. The data is for one month only and each month min and max dates are different. i have to use those to define "one month", i cannot use standard months. So lets say its Jan 2 - Jan 30. if at the end of the month its not a complete 7 day period, use whatever days are left to create the last week.

the key is to build those 7 day time slots in a programmatic way which i am short-handed with. I am thinking CTEs or maybe a table variable but the logic is escaping me. Any gurus can shed some pointers?

Thanks!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-04-08 : 21:08:23
the 7 days is it a fixed window with reference from the min date or it is a moving window ?

What is the expected result for :

RowID Date
1 2010-04-02
2 2010-04-08
3 2010-04-10
4 2010-04-16



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -