Skip to content

Instantly share code, notes, and snippets.

@morbidcamel101
Created June 6, 2019 18:40
Show Gist options
  • Save morbidcamel101/e7201579d4d87f3c7450101b26edd3ce to your computer and use it in GitHub Desktop.
Save morbidcamel101/e7201579d4d87f3c7450101b26edd3ce to your computer and use it in GitHub Desktop.
Generate a range of numbers for insersion SQL
DECLARE
@X INT = 1
,@Y INT = 1000
SELECT ones.n + 10*tens.n + 100*hundreds.n + 1000*thousands.n
FROM (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) ones(n),
(VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) tens(n),
(VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) hundreds(n),
(VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) thousands(n)
WHERE ones.n + 10*tens.n + 100*hundreds.n + 1000*thousands.n BETWEEN @X AND @Y
ORDER BY 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment