Skip to content

Instantly share code, notes, and snippets.

@benjaminkwilliams
Created October 13, 2018 15:19
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 benjaminkwilliams/87e54af97d652e0b208970a7a0494638 to your computer and use it in GitHub Desktop.
Save benjaminkwilliams/87e54af97d652e0b208970a7a0494638 to your computer and use it in GitHub Desktop.
T-SQL FizzBuzz
WITH tally (x) AS
(
SELECT 1
UNION ALL
SELECT x + 1
FROM tally
WHERE x < 100
)
SELECT
CASE
WHEN x % 15 = 0 THEN 'FizzBuzz'
WHEN x % 3 = 0 THEN 'Fizz'
WHEN x % 5 = 0 THEN 'Buzz'
ELSE CONVERT(CHAR(3), x)
END
FROM tally
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment