Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

what does the second @@error return? Expand / Collapse
Author
Message
Posted Saturday, April 24, 2010 7:41 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, May 06, 2011 9:33 AM
Points: 16, Visits: 20
Comments posted to this topic are about the item what does the second @@error return?
Post #910074
Posted Monday, April 26, 2010 2:24 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued 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)
Post #910235
Posted Monday, April 26, 2010 4:00 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: 2 days ago @ 9:27 AM
Points: 359, Visits: 890
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.
Post #910263
Posted Monday, April 26, 2010 4:10 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued 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
Post #910268
Posted Monday, April 26, 2010 5:16 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 5:59 AM
Points: 11,168, Visits: 10,931
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
Post #910290
Posted Monday, April 26, 2010 8:14 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 11:09 AM
Points: 2,744, Visits: 686
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.
Post #910398
Posted Monday, April 26, 2010 8:19 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 2:11 PM
Points: 2,411, Visits: 3,440
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.
Post #910405
Posted Monday, April 26, 2010 8:28 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, April 10, 2014 3:12 PM
Points: 2,132, Visits: 3,399
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!
Post #910416
Posted Monday, April 26, 2010 8:41 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 12:38 PM
Points: 2,290, Visits: 2,545
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


-------------------
"Operator! Give me the number for 911!" - Homer Simpson

"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
Post #910429
Posted Monday, April 26, 2010 8:54 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 1:16 PM
Points: 20,462, Visits: 14,091
I like the question. Nice job.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #910451
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse