--该方法依次类推,可以构造其他有规律的数据集合
--经常遇到的问题
--例如给定一个开始时间,需要计算从开始时间到现在的连续时间
--测试语句
declare @StartTime as datetime
set @StartTime=2005-6-1
declare @t table(dDate datetime) --计算连续时间
while @StartTime<=getdate()
begin
insert into @t select @StartTime
set @StartTime=Dateadd(day,1,@StartTime)
end
--测试结果
dDate
------------------------------------------------------
2005-06-01 00:00:00.000
2005-06-02 00:00:00.000
2005-06-03 00:00:00.000
2005-06-04 00:00:00.000
2005-06-05 00:00:00.000
2005-06-06 00:00:00.000
2005-06-07 00:00:00.000
2005-06-08 00:00:00.000
2005-06-09 00:00:00.000
2005-06-10 00:00:00.000
2005-06-11 00:00:00.000
2005-06-12 00:00:00.000
2005-06-13 00:00:00.000
2005-06-14 00:00:00.000
2005-06-15 00:00:00.000
2005-06-16 00:00:00.000
2005-06-17 00:00:00.000
2005-06-18 00:00:00.000
2005-06-19 00:00:00.000
2005-06-20 00:00:00.000
2005-06-21 00:00:00.000
2005-06-22 00:00:00.000
2005-06-23 00:00:00.000
2005-06-24 00:00:00.000
2005-06-25 00:00:00.000
2005-06-26 00:00:00.000
2005-06-27 00:00:00.000
2005-06-28 00:00:00.000
2005-06-29 00:00:00.000
2005-06-30 00:00:00.000
2005-07-01 00:00:00.000