Created
September 13, 2017 08:18
-
-
Save jsnape/aec4c3ab822bcea93d81b91965be774e to your computer and use it in GitHub Desktop.
CTE as a sequence generator
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
declare @start int = 0; | |
declare @end int = 1000; | |
with numberSequence | |
as ( | |
select @start as nextValue | |
union all | |
select nextValue + 1 | |
from numberSequence | |
where nextValue + 1 < @end | |
) | |
select *, dateadd(day, nextValue, cast('2000-01-01' as date)) as dateValue | |
from numberSequence | |
option (maxrecursion 32767); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment