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
 Transact-SQL (2000)
 Get Period of Dates

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-30 : 08:00:17
Ryan writes "Hi,

Just wonder if i can get a period of dates to be inserted into a temp table (with a single field [Sales_Date]) base on a Start and End Date using a select query?

For Eg,

Start = '8/1/2005', End = '8/5/2005'

In the temp table,
8/1/2005
8/2/2005
8/3/2005
8/4/2005
8/5/2005

Your help is appreciated. Thks.

Rgds
Ryan"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-30 : 08:11:02

Create table #date(d datetime)

Declare @startDate Datetime, @EndDate Datetime
Set @startDate ='2005-08-01'
Set @EndDate ='2005-08-05'

While DateDiff(d,@startDate,@EndDate)>=0
Begin
Insert into #date values (@startDate)
set @startDate=DateAdd(d,1,@startDate)
End

Select d from #date

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -