Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

table to hold weeks in the year 1

Status
Not open for further replies.

lymi6977

IS-IT--Management
Jan 14, 2005
16
US
Can someone tell me the syntax to create a SQL table that would calculate weeks in a year, using Saturday as the week ending date?

Example of data in proposed table:

Week_num Week_end_date
01 01/08/2005
02 01/15/2005
03 01/22/2005
... and so on

Thanks.
Sheila
 
Here's one method. Good luck!

Code:
CREATE TABLE #Dates (
	Week_Num	int,
	Week_End_Date	datetime
			)

DECLARE @cntr int
SET @cntr = 0

WHILE @cntr <= 52
BEGIN
	INSERT INTO #Dates
	SELECT @cntr, DateAdd(week, @cntr, '01-08-2005')
	
	SET @cntr = @cntr + 1
END

SELECT * FROM #Dates

DROP TABLE #Dates

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top