Created
October 13, 2018 15:19
-
-
Save benjaminkwilliams/87e54af97d652e0b208970a7a0494638 to your computer and use it in GitHub Desktop.
T-SQL FizzBuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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