Skip to content

Instantly share code, notes, and snippets.

@binki
Last active September 2, 2019 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binki/9b7985c8832e1545d61cafaa669e3c28 to your computer and use it in GitHub Desktop.
Save binki/9b7985c8832e1545d61cafaa669e3c28 to your computer and use it in GitHub Desktop.
Counting to 100 with recursive CTEs in SQL Server
WITH number AS (SELECT
CAST(1 AS BIGINT) Value
UNION ALL SELECT
n.Value + 1
FROM number n
WHERE n.Value < 100)
SELECT n.Value
FROM number n
ORDER BY n.Value
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment