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.
Author |
Topic |
sql2013
Starting Member
3 Posts |
Posted - 2013-04-01 : 09:35:33
|
I have the following table with specific date ranges and related periods. The actual table has data for all years until 2012.StartDate EndDate Year Period2008-01-01 2008-01-26 2008 12008-01-27 2008-02-23 2008 22008-02-24 2008-03-22 2008 32008-03-23 2008-04-19 2008 42008-04-20 2008-05-17 2008 52008-05-18 2008-06-14 2008 62008-06-15 2008-07-12 2008 72008-07-13 2008-08-09 2008 8.....2008-11-30 2008-12-31 2008 132009-01-01 2009-01-24 2009 1How do I split this table into a table like the one below using T-SQL?Year Period StartofWeek EndofWeek2008 1 2008-01-01 2008-01-052008 1 2008-01-06 2008-01-122008 1 2008-01-13 2008-01-192008 1 2008-01-20 2008-01-26.... 2008 13 2008-11-30 2008-12-062008 13 2008-12-07 2008-12-132008 13 2008-12-14 2008-12-202008 13 2008-12-21 2008-12-272008 13 2008-12-28 2008-12-312009 1 2009-01-01 2009-01-032009 1 2009-01-04 2009-01-10...The week starts on Sundays and ends on Saturdays. But, the end of the week would not carry over for a year. It would end with the last day of the calendar year. And a new period starts again for the new year, for example 2009 above. Please let me know if you need moe details. |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
sql2013
Starting Member
3 Posts |
Posted - 2013-04-01 : 10:14:06
|
Thanks.I created the F table but not sure it will help me.For example, for 2009-01-01, I need a WeekStart date of 2009-01-01 and WeekEnd of 2009-01-03.I dont want the previous year's WeekStart date of 2008-12-28. |
|
|
sql2013
Starting Member
3 Posts |
|
|
|
|