Skip to content

Instantly share code, notes, and snippets.

@jsnape
Created September 13, 2017 08:18
Show Gist options
  • Save jsnape/aec4c3ab822bcea93d81b91965be774e to your computer and use it in GitHub Desktop.
Save jsnape/aec4c3ab822bcea93d81b91965be774e to your computer and use it in GitHub Desktop.
CTE as a sequence generator
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