|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 2:24 AM
Points: 1,871,
Visits: 2,692
|
|
Comments posted to this topic are about the item T-SQL Logic
---------------------------------------------- Msg 8134, Level 16, State 1, Line 1 Divide by zero error encountered.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Monday, September 17, 2012 7:30 AM
Points: 1,038,
Visits: 679
|
|
| simple one, just need to analyse the Query.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 11:51 AM
Points: 5,232,
Visits: 7,023
|
|
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!
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: 2 days ago @ 2:53 AM
Points: 1,526,
Visits: 359
|
|
and database_id < 2
this was enough to answer the question...
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 2:24 AM
Points: 1,871,
Visits: 2,692
|
|
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 
---------------------------------------------- Msg 8134, Level 16, State 1, Line 1 Divide by zero error encountered.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 9:52 AM
Points: 1,356,
Visits: 4,761
|
|
| 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.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Thursday, May 24, 2012 4:01 AM
Points: 318,
Visits: 154
|
|
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
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 6:46 AM
Points: 1,074,
Visits: 1,130
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 3:05 PM
Points: 2,117,
Visits: 2,209
|
|
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
------------------- "The chemistry must be respected." - Walter White
"A SQL query walks into a bar and sees two tables. He walks up to them and says 'Can I join you?'" Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 1:42 PM
Points: 2,012,
Visits: 2,839
|
|
And the point is?... lost on me... again.
|
|
|
|