日期:2014-05-17 浏览次数:20659 次
把2013换成变量,改改就好
insert tb
select distinct dateadd(day,number,'20130101')
from master..spt_values
where number>=0 and number<=365
and dateadd(day,number,'20130101') <'20140101'
and dateadd(day,number,'20130101') not in (select date from tb)
CREATE TABLE #temp (date DATETIME);
DECLARE @year INT
SET @year=2013
;
WITH a1 AS
(
SELECT CAST(RTRIM(@year)+'-01-01' AS DATETIME) date
UNION ALL
SELECT DATEADD(dd,1,date) FROM a1 WHERE DATEPART(yy,DATEADD(dd,1,date))=@year
)
INSERT #temp
SELECT date FROM a1
EXCEPT
SELECT date FROM #temp
OPTION(MAXRECURSION 0)