February 13, 2008 at 1:50 pm
Hi Guys
I have a dates table but i just realized that some years are missing from the table
I need to create a dates table with dates starting from 1990 till 2017
I had a look at some previous posts but they were too complicated to understand.
Can you help me please??
Thanks a tonne
February 13, 2008 at 2:44 pm
I assume you just want the date in the table.
CREATE TABLE YourDate (DateCol DATETIME)
DECLARE @StartDate DATETIME,
@EndDate DATETIME,
@WorkDate DATETIME
SET @StartDate = '01/01/1990'
SET @EndDate = '12/31/2017'
SET @WorkDate = '01/01/1990'
WHILE @WorkDate <= @EndDate
BEGIN
INSERT INTO YourDate(DateCol) SELECT @WorkDate
SET @WorkDate = DATEADD(DD, 1, @WorkDate)
END
February 13, 2008 at 3:39 pm
Nuts,
I always like to see what people have up their sleeves for date and other utility tables... would you mind generating/posting the CREATE statement for your date table and maybe even posting the first 10 rows from the table?
Thank you in advance... I'd really appreciate it.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 1, 2008 at 10:42 pm
Heh... considering that it's been over two weeks, I guess you do mind.
Thanks, anyway 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply