Possible Duplicate:
SQL Server 2008 Generate a Series of date times
I have to Loop through a startDate and endDate
The SELECT statement should produce result as..
Expected Output :
------------
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 its not working out..
it generates 30 outputs..
i want the dates in a single output as in the expected output..
where am i going wrong here guys ?