I need to generate either a column in a query or a temp table (not sure which one is required)
so that I can have a list of dates that are on Saturday that fall within a given date range.
This list will be used in a join to associate records with weeks.
What are my options?
Sample Input:
From: 03/01/2013
To: 04/30/2013
Results:
Week Ending - 03/02/2013 - 03/09/2013 - 03/16/2013 - 03/23/2013 - 03/30/2013 - 04/06/2013 - 04/13/2013 - 04/20/2013 - 04/27/2013 - 05/04/2013
Current code:
create table #TBL7(YEAR INT, WEEKNUMBER INT, STARTDATE DATETIME, ENDDATE DATETIME)
begin
declare @startdate datetime
, @enddate datetime
, @ctr int
SET @startdate = CAST(2013 AS VARCHAR)+ '/01/01'
SET @enddate = CAST(2013 AS VARCHAR) + '/12/31'
SET @ctr = 0
WHILE @enddate >= @startdate
BEGIN
SET @ctr = @ctr + 1
INSERT INTO #TBL7
values(year(@startdate), @ctr, @startdate, @startdate + 6)
SET @startdate = @startdate + 7
END
end
select * from #TBL7