NULLIF 1

  • Thanks for the question. Never used NULLIF, so forced me to investigate.

    I got my point, but am inclined to agree with those that feel that the question could have been presented in a bit more straightforward manner, and still have achieved the same end.

    [font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
    Connect to me on LinkedIn

  • I have to agree with every one else. The select statement is confusing.

    First you start off with the declaration

    "What values are returned for Test 1 and Test 2? " which is invalid because there are 3 columns.

    Then "The values are listed as ID, TEST1, TEST2. For example: "

    Then a four column select. What was the point of making a four column select, just make it line up with the answer.

  • Having a different number of columns in the query vs. the answers is wrong. In no case would the query supplied have a 2nd column return NULL. I know how NULLIF works and have used it. IN my opinion this is one of the worst QotD's I've seen.

  • I agree with Imrann. Today's question is badly framed and confusing....

    but, thanks to the question, I learnt the use of NullIf

  • By the way:

    I often use NULLIF when 3rd party application use MAGIC VALUES instead of NULL.

    e.g. 1799-12-31 stands for NULL DATETIME.

    Here's a generic example to get an actual price:

    SELECT cArticle,mPrice FROM tbPrices

    WHERE GETDATE() BETWEEN dtStart AND ISNULL(NULLIF(dtEnd,'1799-12-31'),GETDATE())

  • The QOD should be vetted and tested before posting for all to answer. None of the answers are correct because the select statement returns 4 columns, not 3. So if you got the point for the question, that's the same as everyone gets a trophy. It counts in your collection, but it has no value.

  • paul.knibbs (6/26/2012)


    I'd agree with Michael--this question seemed to be unnecessarily obfuscated and was more about reading comprehension than anything SQL related, IMHO.

    Agreed. The question is poorly constructed, with part of the requirements outside of the image, and part of them in the image.

    _________________________________
    seth delconte
    http://sqlkeys.com

  • I completely agree with many other peers.

    My first answer was that none of them could be returned by that query (4 cols in select statement, only 3 values per row.. WTF)

    So because I had to choose at least one (mandatory) then I read the explanation...

    Moral for this QotD ? Read everything before answering.

    PD. Better questions will bring better answers.

  • Very interesting question.

    Thanks for sharing.:-)

  • Thanks for the question. I never used nullif before however I do recall seeing it in some Oracle sql before.

  • I have to concur with the majority. When you actually run that query and get the four columns the second and fourth rows are completely wrong in SQL 2008 which is where the question cites as a reference.

    But technically none of the answers are correct, since none of the column values are suppressed as intimated in the answer.

    Just my .02.

    Peace,

    David

  • Thomas Abraham (6/26/2012)


    Thanks for the question. Never used NULLIF, so forced me to investigate.

    I got my point, but am inclined to agree with those that feel that the question could have been presented in a bit more straightforward manner, and still have achieved the same end.

    Ditto (and thank you, Carlo, for explaining when NULLIF() might be useful).

    Moral: Bless Professor Abraham, and you will be blessed. 🙂

  • Great QotD, Ron. Thanks!

  • Good question, though I agree it is not properly worded both in the question and in the answer.

    "El" Jerry.

    "El" Jerry.

    "A watt of Ottawa" - Gerardo Galvan

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

  • Favorite use for NullIf is to prevent a divide by zero:

    Select Miles / Nullif( Hours, 0 ) as Speed

    From SomeTable

    Wasn't thrilled with the formulation of the questions, but I don't think it was designed to confuse. Likely, the image was inadvertently taken with the extra column and the note at the top was designed to rectify the problem.

    Not a big fan of the "image instead of text" questions...

    Seems like plenty of people learned about a function they weren't aware of, so the question served a purpose despite its flaws.

Viewing 15 posts - 16 through 30 (of 52 total)

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