So SQL is Turing complete
Can /g/ code Fizzbuzz in SQL?
>>51742432
DROP
MY
TABLES
I was interviewing a database dev once.
I asked him to code Fizzbuzz. He coded it, but in C. I told him he is a database dev so he should use SQL. This guy was seriously claiming to be a database dev without being able to code Fizzbuzz in a database language.
As he stormed out he could be overhead screaming "eww math" while telling Fizzbuzz to burn in a fire.
No but I can code a fizzbuzz in MS Word
>>51742478
MIXTAPE
>>51742513
If you're not just manually writing it all out then I'm curious.
DECLARE @counter INT
DECLARE @output VARCHAR(8)
SET @counter = 1
WHILE @counter < 101
BEGIN
SET @output = ''
IF @counter % 3 = 0
SET @output = 'Fizz'
IF @counter % 5 = 0
SET @output = @output + 'Buzz'
IF @output = ''
SET @output = @counter
PRINT @output
SET @counter = @counter + 1
END
From the internets, because I'm lazy. It's nothing new, though - you're using the variable features of (in this case, T-SQL) your brand of SQL to do it like you would in any programming language.
>>51742562
posting from mobile so i'm not going to fully tidy that up for you. howeverdeclare @counter int = 1is a more concise way to declare and initialize a variable.set @counter += 1is neater way to to increment a variable's value.
you could neaten up your conditional statements with if/elseif/else.
also you really should indent. correct indentation improves legibility.
3/10
>>51742825
The guy I stole the script from was writing it for an old version of SQL Server. I didn't do anything other than verify the logic looks correct... but, yes, you are correct. The better way in current T-SQL is to declare it with the initial value.
>>51742845
i've had enough of your excuses, watkins. see me after class.
I don't think SQL itself is turing complete, however languages like t/SQL and pl/SQL are