[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
So SQL is Turing complete Can /g/ code Fizzbuzz in SQL?
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 13
Thread images: 1
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. however
declare @counter int = 1
is a more concise way to declare and initialize a variable.
set @counter += 1
is 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
Thread replies: 13
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.