Last active
May 10, 2017 15:09
-
-
Save viktor-evdokimov/d4cb8115e1e4cc65da418d53e213cd50 to your computer and use it in GitHub Desktop.
recursive CTE to get next 10 days
This file contains 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
;with recursive t(n) as ( SELECT now() n union all select n + '1 day' from t where n < '2033-01-01') select * from t limit 10; | |
-- also this works | |
;with recursive t(n) as ( SELECT now() n union all select n + '1 day' from t) select * from t limit 1000; |
This file contains 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
;with t as ( SELECT getdate() n union all select DATEADD(dd, 1, n) from t where n < '2033-01-01') select TOP 10 * from t; | |
-- interesting that this works: | |
;with t as ( SELECT getdate() n union all select DATEADD(dd, 1, n) from t ) select TOP 101 * from t; | |
-- but this not | |
;with t as ( SELECT getdate() n union all select DATEADD(dd, 1, n) from t ) select TOP 102 * from t; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment