Skip to content

Instantly share code, notes, and snippets.

@tompazourek
Last active August 16, 2018 12:49
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 tompazourek/30f6a5fc3987b72df63895a8d639a946 to your computer and use it in GitHub Desktop.
Save tompazourek/30f6a5fc3987b72df63895a8d639a946 to your computer and use it in GitHub Desktop.
Numbers from 0 to 9999.
WITH [Numbers] AS
(
SELECT
[Ones].[Number] +
10 * [Tens].[Number] +
100 * [Hundreds].[Number] +
1000 * [Thousands].[Number]
AS [Number]
FROM (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) [Ones]([Number]),
(VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) [Tens]([Number]),
(VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) [Hundreds]([Number]),
(VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) [Thousands]([Number])
)
SELECT * FROM [Numbers] ORDER BY 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment