Skip to content

Instantly share code, notes, and snippets.

@ststeiger
Created January 25, 2016 16:10
Show Gist options
  • Select an option

  • Save ststeiger/db76b7f3c2fc87367a5b to your computer and use it in GitHub Desktop.

Select an option

Save ststeiger/db76b7f3c2fc87367a5b to your computer and use it in GitHub Desktop.
Create a number series in SQL
DECLARE @start int
DECLARE @end int
SET @start = 3
SET @end = 4
;WITH CTE AS
(
SELECT @start AS zahl
WHERE @start <= @end
UNION ALL
SELECT zahl + 1 AS zahl FROM CTE
WHERE zahl < @end
)
SELECT *
FROM CTE
OPTION (MAXRECURSION 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment