Caution Read comments about DATEFIRST . It depends on your culture ...
According to my comment on your question, this is a way to introduce such a table of launch numbers starting from 1900-01-01, sometime in 2173.
CREATE TABLE dbo.RunningNumbers(Number INT NOT NULL ,CalendarDate DATE NOT NULL ,CalendarYear INT NOT NULL ,CalendarMonth INT NOT NULL ,CalendarDay INT NOT NULL ,CalendarWeek INT NOT NULL ,CalendarYearDay INT NOT NULL ,CalendarWeekDay INT NOT NULL); DECLARE @CountEntries INT = 100000; DECLARE @StartNumber INT = 0; WITH E1(N) AS(SELECT 1 FROM(VALUES (1),(1),(1),(1),(1),(1),(1),(1),(1),(1))t(N)),
This will result in the current Monday:
SELECT * FROM dbo.RunningNumbers WHERE CalendarYear = 2015 AND CalendarWeek = 37 AND CalendarWeekDay=1
Hint: indexes must be specified!
Shnugo Sep 09 '15 at 8:36 2015-09-09 08:36
source share