Predict output

  • Comments posted to this topic are about the item Predict output

  • I would actually disagree with the answer given ...

    Strictly speaking, the output is:

    this is an exception ... in the messages pane ...

    and then

    1

    2

    4

    5

    in the results pane.

    To my mind, the timing is important, as the "1,2,4,5" results are output AFTER the error message??

  • Actullay the answer shoul be

    this is an exception

    id

    -----------

    1

    2

    4

    5

  • There's been a bit of a biff about QoD answers lately, but there is really only one answer today as "this is an exception" will be output and only one choice offers that. The others either include "3" (which is not output) or do not complete the loop (which still happens.)

    S.

  • none of the suggested answers gives what I would call the correct output, which is a result of:

    1,2,4,5

    the following would be the messages created:

    (1 row(s) affected)

    (1 row(s) affected)

    this is an exception

    (1 row(s) affected)

    (1 row(s) affected)

    (4 row(s) affected)

  • I have to agree here. None of the answers match what I would expect, which would be 'This is an exception' in the message pane, followed by the contents of the temp table: 1, 2, 4, 5.

    However, when I ran this to try it out, I got an error:

    (1 row(s) affected)

    (1 row(s) affected)

    this is an exception

    Msg 208, Level 16, State 0, Line 10

    Invalid object name '#temp'.

    Which indicates that despite the try-catch block, the error caused the temp table to be dropped mid-execution.

  • Changing result to be in text, I get

    (1 row(s) affected)

    (1 row(s) affected)

    this is an exception

    (1 row(s) affected)

    (1 row(s) affected)

    id

    -----------

    1

    2

    4

    5

    (4 row(s) affected)

    -------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
    There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
    I would never join a club that would allow me as a member - Groucho Marx

  • mzz3lh (1/20/2010)


    I have to agree here. None of the answers match what I would expect, which would be 'This is an exception' in the message pane, followed by the contents of the temp table: 1, 2, 4, 5.

    However, when I ran this to try it out, I got an error:

    (1 row(s) affected)

    (1 row(s) affected)

    this is an exception

    Msg 208, Level 16, State 0, Line 10

    Invalid object name '#temp'.

    Which indicates that despite the try-catch block, the error caused the temp table to be dropped mid-execution.

    I ran this on sql server 2008 and did not get that behavior

  • Yeah, I assumed SQL2008 might have been ok for this. I ran it on SQL2005 and got the error.

    The Rollback Transaction statement seems to drop the temp table.

  • mzz3lh (1/20/2010)


    However, when I ran this to try it out, I got an error:

    (1 row(s) affected)

    (1 row(s) affected)

    this is an exception

    Msg 208, Level 16, State 0, Line 10

    Invalid object name '#temp'.

    Probably the IMPLICIT_TRANSACTIONS option is turned on.

    Try this code:

    SET IMPLICIT_TRANSACTIONS OFF

    GO

    ... here comes the original script ...

  • vk-kirov (1/20/2010)


    mzz3lh (1/20/2010)


    However, when I ran this to try it out, I got an error:

    (1 row(s) affected)

    (1 row(s) affected)

    this is an exception

    Msg 208, Level 16, State 0, Line 10

    Invalid object name '#temp'.

    Probably the IMPLICIT_TRANSACTIONS option is turned on.

    Try this code:

    SET IMPLICIT_TRANSACTIONS OFF

    GO

    ... here comes the original script ...

    Good call, cheers. I had it switched on without realising, so the create table statement was obviously not autocommitting.

    I still think the options in the question were wrong though, even after running the code successfully. The third option implied the 'this is an exception' string formed part of the table data, when clearly it was a printed message.

  • OK OK OK, so here I am once again complaining!

    When I studied this question, I thought: "Well, the only values inserted into the table, will be 1, 2, 4 and 5. So, before going to the webpage to select my answer, I expected to see "1, 2, 4, 5" as an option.

    But when I got to the website, there was no such option available, but there was one where the third value on the list was a string 'This is an exception'. I selected that option as a compromise, and got the points.

    "BUT", I thought, "this string can't be inserted into the database, although it will be in the message list." So I had selected the option which would be in my message list rather than the output of the query, which wasn't shown as an option anyway. Of course I had gained the two points but I wasn't happy with the options given.

    And the moral of this story: would future question submittees please distinguish between message output and query output. Or better still would the question editors (although there don't seem to be any editors anyway) please check the quality of questions and use a little editorial blue-pencil where necessary.

    All the best

    Ken.

    You never know: reading my book: "All about your computer" might just tell you something you never knew!
    lulu.com/kaspencer

  • the given answers are incorrect....when i execute the code(SQL 2005)....it gives me the result as 1,2,4,5 and this is an exception message. It is annoying to see incorrect options....;-)

  • mzz3lh (1/20/2010)


    I have to agree here. None of the answers match what I would expect, which would be 'This is an exception' in the message pane, followed by the contents of the temp table: 1, 2, 4, 5.

    However, when I ran this to try it out, I got an error:

    (1 row(s) affected)

    (1 row(s) affected)

    this is an exception

    Msg 208, Level 16, State 0, Line 10

    Invalid object name '#temp'.

    Which indicates that despite the try-catch block, the error caused the temp table to be dropped mid-execution.

    Or that something was wrong with the code you ran. It ran fine for me, and it appears from a few other posts that it ran fine for others.

    I agree, the answers may not have been displayed as many of us have seen it when we ran the code. The question is, were you able to correctly predict the output? In this case, as mentioned in another post, there really was only one option that could be correct. It may have been more difficult had there been one or two more possible answers with the exception message included.

  • To all those who are expecting PRECISELY CORRECT ANSWERS, how about putting yourself out there and submit some questions. The answers may not have been precise, but I don't feel that it really took that much away from the question. What was important was seeing that using the TRY/CATCH kept the while loop from being aborted, allowing you to control the processing within SQL itself.

Viewing 15 posts - 1 through 15 (of 54 total)

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