Possible duplicate:
SQL Server 2008 Create a series of time dates
I need to loop through startDate and endDate
The SELECT statement should return the result as ..
Expected Result:
Date
09/01/2012 -> startDate
09/02/2012
09/03/2012
.
.
.
.
09/30/2012 -> endDate
I tried
declare @startDate datetime , @endDate endDate
set @startDate='09/01/2012'
set @endDate='09/30/2012'
while DATEDIFF(@startDate,@endDate)!=-1
begin
select @startDate as Date
set @startDate = DATEADD(day,2,@startDate)
end
But it doesn’t work out ..
It generates 30 outputs.
I need dates in one output, as in the expected output.
where am I going wrong guys?
source
share