作者:不想不知痛_378 | 来源:互联网 | 2023-08-12 13:43
PossibleDuplicate:SQLServer2008GenerateaSeriesofdatetimes可能重复:SQLServer2008生成一系列日期
Possible Duplicate:
SQL Server 2008 Generate a Series of date times
可能重复:SQL Server 2008生成一系列日期时间
I have to Loop through a startDate and endDate
我必须遍历startDate和endDate
The SELECT statement should produce result as..
SELECT语句应该生成结果为..
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..
它产生30个输出..
i want the dates in a single output as in the expected output..
我希望单个输出中的日期与预期输出中的日期相同。
where am i going wrong here guys ?
我在哪里错了?
3 个解决方案