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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

temporary table 1

Status
Not open for further replies.

mgreer

Programmer
Jan 9, 2001
45
0
0
US
In a stored procedure I need to create a temporary table that has one column (date). Then I need to insert every day for the past... let's say year. So I need an entry for every day from 1/1/2002 to the current day.

I know how to create the table but am having trouble getting the data into the table. Anyone have any ideas on how to do this?

thanks
 
Hi,

Try this Code.....


Declare @NoofDays int
Declare @StartDate datetime
Set @StartDate = '01/01/02'
Set @NoofDays = Datediff(day,@startdate,getdate())
print @NoofDays
Create table #datetbl
(adate datetime)
While @NoofDays >= 0
Begin
insert into #dateTbl values(getdate()- @NoofDays)
Set @NoofDays =@NoofDays -1
End


select * from #dateTBL

drop table #dateTBL

Sunil
 
That works beautifully. Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top