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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 fill datetime table

Author  Topic 

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2008-05-07 : 08:56:13
hi,

i have a empty table:
CREATE table time
(id int identity(1,1)
,time_entry smalldatetime
,year int not null
,month int not null
,day int not null
)

and i want to fill it dates from 1/1/2008 until today :)

any fast way to do it? :)

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-05-07 : 09:00:44
Make use of F_Table_Date function here: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=61519&SearchTerms=F_TABLE_DATE

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2008-05-07 : 09:15:21
made it like:

declare @int int
set @int = 1953;
print @int;

while @int <= 1953
begin
insert into time (time_entry, year, month, day) values (getdate()-@int, year(getdate()-@int), month(getdate()-@int), day(getdate()-@int))
print @int;
set @int = @int - 1
end
print 'Insert finished'
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-07 : 10:05:57
or even this:-

DECLARE @StartDate datetime
SET @StartDate='01/01/2008'
SELECT DATEADD(dd,v.number,@StartDate)
FROM master..spt_values
WHERE type='p'
AND DATEADD(dd,v.number,@StartDate)< GETDATE()
Go to Top of Page
   

- Advertisement -