--每天记录
DECLARE @start DATE,@end DATE
SET @start='2020-7-1'
SET @end='2020-7-20'
select
DATEADD(DAY,number,@start) ymd
from master..spt_values
where type='p' AND
number<=DATEDIFF(day,@start,@end)
--每周记录
DECLARE @start DATE,@end DATE
SET @start='2020-6-1'
SET @end='2020-7-1'
select
DATEADD(WEEK,number,@start) ymd
from master..spt_values
where type='p' AND
number<=DATEDIFF(WEEK,@start,@end)
--每月记录
DECLARE @start DATE,@end DATE
SET @start='2019-1-1'
SET @end='2020-7-1'
select
DATEADD(MONTH,number,@start) ymd
from master..spt_values
where type='p' AND
number<=DATEDIFF(MONTH,@start,@end)
--每年记录
DECLARE @start DATE,@end DATE
SET @start='2019-1-1'
SET @end='2020-7-1'
select
DATEADD(year,number,@start) ymd
from master..spt_values
where type='p' AND
number<=DATEDIFF(year,@start,@end)