• kaspencer (1/5/2010)


    I couldn't see the answer to this question, and so I guessed "C" which happened to be correct.

    However, when I tried the three options on my system, "C" returned an error, "B" also returned an error, and "A" returned NULL.

    I suspect that my errors had a similar cause to that reported by others. This leads me to make a suggestion for consideration by the adjudicators (if there are any!):

    I suggest that before allowing a question to be used, the submitter must ensure that all assumptions and pre-conditions for the question be stated clearly. These assumptions would include such items as database names, table existence, as well as any security or user-privilege features necessary to ensure that the correct response would be produced when the query or procedure is run.

    I have noted many instances of reports in this forum when queries have failed (and have had some such myself), and I feel that this shows poor appreciation by the submitter that not every system resembles his own.

    Happy New Year to one and all!

    Ken.

    I disagree. If you want to run the code in your environment, you should take the appropriate steps based on the code to ensure that it runs. I ran the code in a sandbox database where I had to make appropriate changes, including commenting code as I ran each option to see what occurred.

    The reason is the same as you mentioned, the person providing a QotD can't know how everyone's environment is setup. Do you have a AdventureWorks installed on your servers at work? I don't. Do you have your databases on your D: drive, or your backup files on the E: drive? There are so many possibilities that it isn't possible for a person to ensure that the code will work on everyones instance of SQL Server.

    After answering the question, I tested the code.

    First option, returned null.

    Second option, an error.

    Third option, correct result based on the table I used in the original modification for the table to query.

    All of that confirmed my original answer of C.