生成日期序列

Oracle中:

select to_date('20120101', 'yyyymmdd') + level - 1 as everyDay
  from dual
connect by level <= (last_day(to_date('20120101', 'yyyymmdd')) -
           to_date('20120101', 'yyyymmdd') + 730)


 

SQLServer中:

Declare @mindate datetime
Declare @maxdate datetime
set @mindate  = '2010-01-01'
set @maxdate  = '2010-02-01';
with temptab(date) as
( select @mindate
union all
select dateadd(d,1,temptab.date) as date
from temptab
where dateadd(d,1,temptab.date)<=@maxdate
)
select * from temptab


 

你可能感兴趣的:(数据库开发)