Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

T-SQL Logic Expand / Collapse
Author
Message
Posted Monday, June 21, 2010 8:17 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, August 28, 2014 2:39 AM
Points: 1,904, Visits: 2,846
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.
Post #940724
Posted Tuesday, June 22, 2010 12:02 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, September 2, 2014 10:39 AM
Points: 1,194, Visits: 787
simple one, just need to analyse the Query.
Post #940769
Posted Tuesday, June 22, 2010 2:04 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 1:36 PM
Points: 6,002, Visits: 8,267
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
Post #940812
Posted Tuesday, June 22, 2010 2:23 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, June 30, 2014 2:51 AM
Points: 2,034, Visits: 369
and database_id < 2

this was enough to answer the question...
Post #940822
Posted Tuesday, June 22, 2010 2:48 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, August 28, 2014 2:39 AM
Points: 1,904, Visits: 2,846
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.
Post #940832
Posted Tuesday, June 22, 2010 3:43 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, August 29, 2014 10:20 AM
Points: 1,740, Visits: 6,366
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.
Post #940871
Posted Tuesday, June 22, 2010 3:44 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, June 14, 2013 8:43 AM
Points: 319, Visits: 156
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
Post #940872
Posted Tuesday, June 22, 2010 6:09 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, February 6, 2014 4:15 AM
Points: 1,242, Visits: 1,546
Another easy point



Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
www.GrowWithSql.com

Post #940966
Posted Tuesday, June 22, 2010 8:04 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 8:20 AM
Points: 2,373, Visits: 2,726
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


-------------------
"Operator! Give me the number for 911!" - Homer Simpson

"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
Post #941065
Posted Tuesday, June 22, 2010 8:06 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 12:58 PM
Points: 2,585, Visits: 3,842
And the point is?... lost on me... again.
Post #941067
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse