Variant order 1

  • Cadavre (11/30/2011)


    Cadavre (11/30/2011)


    Got it wrong because I believe it should say "v3 = v2" not "v2 = v3"

    L' Eomot Inversé (11/30/2011)


    wloong (11/29/2011)


    I agreed!

    From the programming logic, "v2 = v3" could not be displayed! In fact, the right answer should be "None of the above". If the editor admit that it is a typo mistake, then both "v2 = v3" and "None of the above" should be correct in order to be fair.

    There isn't a typo. The select statement as written can't return v2=v3 in any of ths ecolumns of the resulting row: as you yourself state, the programming logic does not permit v2 = v3 to be displayed, so how could it imaginably be correct to say it return v2 = V3 in one of the columns?

    If you run the code you will certaily see that "none of the above" is not the correct answer, because it returns one of the rows listed.

    Yes Tom, but the "correct" answer states v2=v3 not v3=v2.

    [/URL]

    I replied too quickly before, didn't cover all bases before getting it wrong. I knew there wasn't a typo in the question, and didn't consider the possibility of one in the answer so didn't compare the anser with the options in the question. Thus compounding my error - the misprint was bad enough, then saying there wasn't one was worse. Mea maxima culpa :blush:

    The only consolation is that it didn't affect anyone's score - as is made clear by the image you attached, 51% of people got it right and were recognised as having it right even though the option they chose didn't match the row given in the answer.

    Must check more carefully before rplying in future :blush:

    Tom

  • L' Eomot Inversé (11/30/2011)


    I replied too quickly before, didn't cover all bases before getting it wrong. I knew there wasn't a typo in the question, and didn't consider the possibility of one in the answer so didn't compare the anser with the options in the question. Thus compounding my error - the misprint was bad enough, then saying there wasn't one was worse. Mea maxima culpa :blush:

    The only consolation is that it didn't affect anyone's score - as is made clear by the image you attached, 51% of people got it right and were recognised as having it right even though the option they chose didn't match the row given in the answer.

    Hmm, I can't view the original question now so can't see the original options but I'm sure the reason I selected "None of the above" was because the option that most closely resembled the answer stated v2=v3 not v3=v2.

    Never mind, the explanation was good 😀


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Cadavre (11/30/2011)


    L' Eomot Inversé (11/30/2011)


    I replied too quickly before, didn't cover all bases before getting it wrong. I knew there wasn't a typo in the question, and didn't consider the possibility of one in the answer so didn't compare the anser with the options in the question. Thus compounding my error - the misprint was bad enough, then saying there wasn't one was worse. Mea maxima culpa :blush:

    The only consolation is that it didn't affect anyone's score - as is made clear by the image you attached, 51% of people got it right and were recognised as having it right even though the option they chose didn't match the row given in the answer.

    Hmm, I can't view the original question now so can't see the original options but I'm sure the reason I selected "None of the above" was because the option that most closely resembled the answer stated v2=v3 not v3=v2.

    Never mind, the explanation was good 😀

    My God, I must be going crazy.

    A big apology from me to everyone. :blush: :blush: :blush: :blush: :blush: :blush:

    The typo in the answer is matched by the typo in the question. Not the bit of the question I could see in the newsletter (it doesn't show me the bits not visible to me on the website, which Of course I should have noticed :blush: :blush:, but as you have pointed out it soes in the bit I could see by looking at the numbers of responses!)

    The only correct answer was "none of the above"!

    I'll ask Steve to fix it - so far I've asked him to change the answer and add version info to the question, now I'm asking him for another change. I guess he will award points back.

    Tom

  • I got this question 'wrong' because the result of my query came back with v3 = v2, not v2 = v3. The value in the result set is a text value. That means that 'v3 = v2' is not the same as 'v2 = v3'. While mathematically it is the same, we are talking about the value of the result set as a text field. If you had not used the comparison as the returned set and had instead used Adam, Betty, Charlie or Apple, Banana, Grape to indicate which When clause had been validated as being true it would be very clear that Betty does not equal Banana. Or, if the when clause that evaluated to true was the percentage of your raise, then you are saying you would be happy with 1.0% instead of 10% because as you pointed out, it doesn't effect anyone's points if they choose None of the Above instead of the row with the typo.

    I've chosen wrong answers before because of small mistakes like this so I check my result set very carefully with the choices. If this had been code that had gone to production with a small typo in the When clause, it can make for even bigger issues.

  • callie97 (11/30/2011)


    I got this question 'wrong' because the result of my query came back with v3 = v2, not v2 = v3. The value in the result set is a text value. That means that 'v3 = v2' is not the same as 'v2 = v3'. While mathematically it is the same, we are talking about the value of the result set as a text field. If you had not used the comparison as the returned set and had instead used Adam, Betty, Charlie or Apple, Banana, Grape to indicate which When clause had been validated as being true it would be very clear that Betty does not equal Banana. Or, if the when clause that evaluated to true was the percentage of your raise, then you are saying you would be happy with 1.0% instead of 10% because as you pointed out, it doesn't effect anyone's points if they choose None of the Above instead of the row with the typo.

    I've chosen wrong answers before because of small mistakes like this so I check my result set very carefully with the choices. If this had been code that had gone to production with a small typo in the When clause, it can make for even bigger issues.

    You are right, there wa a typo in the option list as well as in the answer. It was absolutely stupid of me to miss that when checking as a result of the first comment this morning, and it does indeed affect people's points.

    Steve will be correcting it and awarding points to people who lost them through my errors.

    Tom

  • rfr.ferrari (11/30/2011)


    good question and explanation!!!!

    thanks Tom!!!

    But terrible answer!!

    Tom

  • The question now reader:

    ====

    Assuming you have a database called playpen on SQL Server 2008 and above, what is the resul of the select statement in the following code?

    use playpen

    go

    begin

    declare

    @v1 sql_variant = cast ('15.00' as float(53)),

    @v2 sql_variant = cast ('15.00' as decimal(18,4)),

    @v3 sql_variant = cast ('15' as tinyint),

    @v4 sql_variant = cast ('00:00:15.00' as time)

    select

    case when @v1 > @v2

    then 'v1 > v2'

    when @v2 > @v1

    then 'v2 > v1'

    else 'v2 = v1'

    end,

    case when @v1 > @v3

    then 'v1 > v3'

    when @v3 > @v1

    then 'v3 > v1'

    else 'v3 = v1'

    end,

    case when @v2 > @v3

    then 'v2 > v3'

    when @v3 > @v2

    then 'v3 > v2'

    else 'v2 = v3'

    end,

    case when @v1 > @v4

    then 'v1 > v4'

    when @v4 > @v1

    then 'v4 > v1'

    else 'v4 = v1'

    end

    end

    ====

    And the answers corrected to:

    A: v2 = v1, v3 = v1, v2 = v3, v4 = v1

    B: error indicating float and time are incompatible

    C: v1 > v2, v1 > v3, v3 > v2, v4 > v1

    D: v1 > v2, v1 > v3, v2 = v3, v4 > v1

    E: v2 = v1, v1 > v3, v2 > v3, v1 > v4

    F: none of the above

    ====

    v2=v3 matches in answers A and D

    Points have been awarded back to everyone to this point.

  • Tom,

    In the e-mail newsletter the QotD did not state it was for SQL Server 2008 and later, so I tested under SQL Server 2005 (the only version I have available to use), which would not allow me to run it because "you cannot assign a default value to a local variable", so i chose "None of the above" just to find out it was meant to be run under SQLS 2K8.

    Just make sure the specifics are included in the newsletter.

    Thank you,

    GG.

    "El" Jerry.

    "A watt of Ottawa" - Gerardo Galvan

    To better understand your help request, please follow these best practices.[/url]

  • Gerardo Galvan Castro (11/30/2011)


    In the e-mail newsletter the QotD did not state it was for SQL Server 2008 and later, so I tested under SQL Server 2005 (the only version I have available to use), which would not allow me to run it because "you cannot assign a default value to a local variable", so i chose "None of the above" just to find out it was meant to be run under SQLS 2K8.

    I'd say, with both SQL Server 2008 and SQL Server 2008R2 released and SQL Server 2012 around the corner, it is safe to assume that question are about SQL Server 2008/2008R2 unless specified otherwise.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • Gerardo Galvan Castro (11/30/2011)


    Tom,

    In the e-mail newsletter the QotD did not state it was for SQL Server 2008 and later, so I tested under SQL Server 2005 (the only version I have available to use), which would not allow me to run it because "you cannot assign a default value to a local variable", so i chose "None of the above" just to find out it was meant to be run under SQLS 2K8.

    Just make sure the specifics are included in the newsletter.

    Thank you,

    GG.

    I should have included the version information in the original question. I didn't, so it didn't get into the newsletter - and everyone who answered up to about 10 minutes ago (when the question on the website was corrected) didn't get any version information whichever way the came to the question. My fault, and no valid excuses.

    But it's a good idea if coming from the newsletter to check that the version on teh website is the same - errare est humanum and all that, and corrections can be applied to the website but can't be applied to the newsletter once it's gone out.

    Tom

  • Interesting question. My brain did the auto translation that v3=v2 was the same as v2=v3 so I didn't even notice that error until I hit the posts here!

    I have not yet seen sql variants actually used in production but then again, we have very few 2008 instances up and running. I am curious how many out there are utilizing sql_variant and under which circumstances?

  • KWymore (11/30/2011)


    I have not yet seen sql variants actually used in production but then again, we have very few 2008 instances up and running.

    There is no connection between sql_variant and SQL Server 2008. This data type has been around since at least SQL Server 2000. (I think even before that, but I could not find evidence of that, and I'm not sure if I can trust my memory anymore).


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • Thanks for the question.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • KWymore (11/30/2011)


    I am curious how many out there are utilizing sql_variant and under which circumstances?

    I've used it for generic audit tables, where we store something like table name, column name, old value, new value - the old/new values are sql_variant as they could be any data type.

    Of course you'd never do any comparisons between different data types in these circumstances.

  • Tks Tom for the question

Viewing 15 posts - 31 through 45 (of 58 total)

You must be logged in to reply to this topic. Login to reply