|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, May 06, 2011 9:33 AM
Points: 16,
Visits: 20
|
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Monday, January 24, 2011 6:23 AM
Points: 64,
Visits: 29
|
|
hi, the below given set of statements given the same error...

select 'def' raiserror('oh no, another error!', 16,1) select 'xyz' select @@error
(1 row(s) affected) Msg 50000, Level 16, State 1, Line 2 oh no, another error!
(1 row(s) affected)
(1 row(s) affected)
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Today @ 10:02 AM
Points: 356,
Visits: 754
|
|
Did this without query analyser.. and got it right, nice. Hi wall str33t,
Nice question!
Hi Charles,
Both queries will give the same error, but the question was asking what was returned in the results, not the messages.
The first query when ran by itself will error (you get messages), and the results panel will show two result sets, the first 'abc' , the second the error result set with the error number.
The second query will have three result sets: 'abc' 'xyz' and 0
Because as wall str33t says the second query executes fine, clears @@error, therefore no error is held in the @@error variable when selected.
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Monday, January 24, 2011 6:23 AM
Points: 64,
Visits: 29
|
|
hi,
yes correct
i missunderstood the question
means i haven't read the question correctly
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 7:18 PM
Points: 10,989,
Visits: 10,532
|
|
A question about SQL today! Well done, and thanks. @@error is a bit less relevant these days (TRY/CATCH) but it's still a good general-knowledge question.
Paul White SQL Server MVP SQLblog.com @SQL_Kiwi
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 8:40 AM
Points: 2,412,
Visits: 578
|
|
| While I see that the answer is correct, I found the question to be confusing, therefore I feel that it was not a good question.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 11:48 AM
Points: 2,015,
Visits: 2,843
|
|
I didn't have to run the code to know the answer, but, what if I did? It still would be a learning experience which is the point of the QotD. I find the negativity against running code to be irritating.
Good question, though. Nicely thought out and very clear as to its intent.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Tuesday, March 19, 2013 6:25 PM
Points: 2,062,
Visits: 3,221
|
|
Good question!
I purposely did not run this in Query Editor, and tried to answer on my own. (I got it right!)
I had to keep in mind that @@ERROR really only applies to the most recent line. From what I saw, SELECT 'XYZ' would not return an error!
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 3:05 PM
Points: 2,117,
Visits: 2,209
|
|
Good question. The phrasing could have been more precise, such as what does the second 'select @@error' statement return, but I think that is beside the point and should not be grounds for criticizing the question. I just plain missed that the select 'xyz' statement resets the @@error value to 0, so it was a good exercise in reading code more carefully.
Thanks, webrunner
------------------- "The chemistry must be respected." - Walter White
"A SQL query walks into a bar and sees two tables. He walks up to them and says 'Can I join you?'" Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Yesterday @ 1:07 PM
Points: 18,733,
Visits: 12,332
|
|
|
|
|