Created
February 6, 2017 20:35
-
-
Save Mikuana/d56818ba8ca39dc871048d9d88ab1326 to your computer and use it in GitHub Desktop.
Generate a TSQL calendar table using all_objects table as a seed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE | |
@cal_start DATE | |
, @cal_end DATE | |
, @n INT | |
; | |
SELECT | |
@cal_start = '1970-01-01' | |
, @cal_end = '2030-12-31' | |
, @n = DATEDIFF(DAY, @cal_start, @cal_end) | |
; | |
WITH | |
seed AS | |
( SELECT TOP (@n) | |
CONVERT(INT, ROW_NUMBER() OVER (ORDER BY s1.object_id)) AS n | |
FROM | |
sys.all_objects AS s1 | |
CROSS JOIN | |
sys.all_objects AS s2 | |
) | |
SELECT | |
DATEADD(DAY, n - 1, @cal_start) AS calendar_date | |
FROM | |
seed | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment