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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Store procedure to get date

Author  Topic 

abarsami
Yak Posting Veteran

68 Posts

Posted - 2002-11-06 : 21:39:56
I need help in writing a stored procedure that get the dates between 2 dates & inserts each date into one temp table

So

@Date = '11/07/2002'
@Date2 = '04/05/2003'

Get every date between @Date and @Date2 and insert into #Temp

#Temp would have

11/07/2002
11/08/2002
11/09/2002
... all the way down to
04/05/2003

Can someone help me?

abarsami
Yak Posting Veteran

68 Posts

Posted - 2002-11-06 : 21:57:29
I figured it out ... never mind

Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-11-06 : 21:58:04
Hi there

Here is some code that will do it (you can add it into your procedure as you see fit)




Create Table #temp (
thedate datetime
)



Declare @StartDate datetime,
@EndDate datetime

Select @StartDate = '1-oct-2002',
@EndDate = '5-Nov-2002'

SET NOCOUNT ON


Declare @NoDays int,
@i int

Set @NoDays = DateDiff(d, @StartDate, @EndDate)
Set @i = 0

While @i <= @NoDays Begin
Insert Into #Temp Values (DateAdd(d, @i , @StartDate))
Set @i = @i + 1
End

SET NOCOUNT OFF

Select * from #temp

Drop Table #temp



Hope that helps

Damian
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-11-06 : 21:58:36
Damn, if only you had waited one more second

Damian
Go to Top of Page
   

- Advertisement -