Tuesday, June 29, 2010

Query to Fill Table with Dates

Here is a simple query to insert dates from 2000-07-03 00:00:00.000 to 2020-06-27 00:00:00.000

with DateCTE as (


SELECT dateadd( dd,-3650 + RW ,DATEADD(dd, DATEDIFF(dd,0,getdate()), 0)) As N

FROM (

SELECT TOP 7300

row_number() OVER (ORDER BY sc1.id) AS RW

FROM Master.dbo.SysColumns sc1

CROSS JOIN Master.dbo.SysColumns sc2

) X

)

--the SQL2008 DATE datatype, instead of datetime

SELECT convert(DATETIME,DateCTE.N)

from DateCTE

No comments:

Post a Comment