June 21, 2010 at 8:17 pm
Comments posted to this topic are about the item T-SQL Logic
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle
June 22, 2010 at 12:02 am
simple one, just need to analyse the Query.
June 22, 2010 at 2:04 am
I hope it is not considered cheating that I did run SELECT database_id, name FROM sys.databases ORDER BY 1;
before answering. I don't thik there is any need for me to know ids of system databases by head.
Other than that, the question was a bit too simple. Just the AND database_id < 2 was sufficient to determine that there would be one result, and there was only one option with one result, so there was no need at all to evaluate the CASE and POWER expressions.
Anyway, thanks for the question Henrico! Your first, I believe? Hopefully there will be more in the future!
June 22, 2010 at 2:23 am
and database_id < 2
this was enough to answer the question...:-)
June 22, 2010 at 2:48 am
Hi Hugo, yes, looking at the last where statement, it was easy to determine the answer.
But, look at the wrong answer rate - 19 so far.
This question was purely to test logic when it comes to reading code, and was not intended to be a massive brain cracker 😀
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle
June 22, 2010 at 3:43 am
I just used the len(case...) statement - since this can return only one row (master) then the answer is the one with only a single option.
June 22, 2010 at 3:44 am
It would have been more interesting if it had read "and database_id <= 2
" which would have brought the case statement into play more.
That's the way I read it anyway. Good thing it had the same answer 🙂
June 22, 2010 at 6:09 am
Another easy point 🙂
Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
June 22, 2010 at 8:04 am
I got this right! I learned my lesson from the last time - after equivocating for a minute, wondering "the choice of 1 is too easy, maybe there's a trick" - I decided that no trick was evident based on the code.
Simple question for many at SSC, I suppose. But still worth looking at and being able to explain for "lesser experts" (i.e., those of us who get too many QOTD questions wrong :-))
- webrunner
-------------------
A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
June 22, 2010 at 8:06 am
And the point is?... lost on me... again.:w00t:
June 22, 2010 at 8:10 am
there are no negative database ids 🙂
and there is no 0
thus 1 is the answer to the most obfuscated question ever!
June 22, 2010 at 8:34 am
Yeah, the question is overly complicated, and the answer is overly simple. The POWER() function is totally unneccessary, its fairly obvious from the WHERE clause that there's only going to be one row result. Not to mention the WHERE clause is redundant, as both branches will select the master database and only that database.
Really, I don't think it's a good question. It's complicated apparently just for the sake of being complicated. Save for learning that the database_id of the master database is always 1, no one will really actually bring anything away from this question.
--J
June 22, 2010 at 8:37 am
I think it's a good question - designed to make you think a bit and work out that you don't actually need to know anything about database ids in order to get it right.
June 22, 2010 at 8:47 am
Nice question. Thanks.
June 22, 2010 at 8:55 am
ziangij (6/22/2010)
and database_id < 2
this was enough to answer the question...:-)
Yes, if 10 would have been a possible answer it would have forced me to at least look at the rest of the Query.
Viewing 15 posts - 1 through 15 (of 22 total)
You must be logged in to reply to this topic. Login to reply