|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Tuesday, July 03, 2012 5:49 AM
Points: 418,
Visits: 365
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, October 17, 2012 9:07 PM
Points: 118,
Visits: 39
|
|
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??
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Saturday, March 30, 2013 6:06 AM
Points: 532,
Visits: 224
|
|
Actullay the answer shoul be
this is an exception id ----------- 1 2 4 5
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, April 03, 2013 10:05 PM
Points: 584,
Visits: 1,571
|
|
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.
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, March 08, 2013 8:32 AM
Points: 26,
Visits: 41
|
|
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)
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, May 07, 2013 8:30 AM
Points: 1,167,
Visits: 206
|
|
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.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 1:41 AM
Points: 2,477,
Visits: 2,140
|
|
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 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
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, March 08, 2013 8:32 AM
Points: 26,
Visits: 41
|
|
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
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, May 07, 2013 8:30 AM
Points: 1,167,
Visits: 206
|
|
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.
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Today @ 6:30 AM
Points: 3,192,
Visits: 4,151
|
|
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 ...
|
|
|
|