首页 > 代码库 > sql日期补全

sql日期补全

</pre><pre name="code" class="sql">IF OBJECT_ID('TBL')IS NOT NULL
DROP TABLE TBL
GO
CREATE TABLE TBL(
日期 DATE
)
GO
INSERT TBL
SELECT '2014-09-30' UNION ALL
SELECT '2014-10-06'

go
DECLARE @DATE DATE
SELECT @DATE=MAX(日期) FROM TBL
;WITH T
AS(
SELECT * FROM TBL
UNION ALL
SELECT DATEADD(DD,1,A.日期) FROM T A
WHERE NOT EXISTS(SELECT * FROM TBL B
WHERE B.日期=DATEADD(DD,1,A.日期)
)
AND A.日期<@DATE
)
SELECT *FROM T ORDER BY 日期


sql日期补全