SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


what does the second @@error return?


what does the second @@error return?

Author
Message
wall str33t
wall str33t
SSC-Enthusiastic
SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)SSC-Enthusiastic (113 reputation)

Group: General Forum Members
Points: 113 Visits: 45
Comments posted to this topic are about the item what does the second @@error return?
charles.prabhu
charles.prabhu
SSC Journeyman
SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)

Group: General Forum Members
Points: 82 Visits: 29
hi,
the below given set of statements given the same error...

Hehe

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)
Fozzie
Fozzie
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1229 Visits: 1172
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.
charles.prabhu
charles.prabhu
SSC Journeyman
SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)

Group: General Forum Members
Points: 82 Visits: 29
hi,

yes correct

i missunderstood the question

means i haven't read the question correctly
Paul White
Paul White
SSC Guru
SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)

Group: General Forum Members
Points: 79630 Visits: 11400
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
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
Patrick Cahill
Patrick Cahill
SSCarpal Tunnel
SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)

Group: General Forum Members
Points: 4406 Visits: 1029
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.
OCTom
OCTom
SSCertifiable
SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)

Group: General Forum Members
Points: 5985 Visits: 4152
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. :-)
Ray K
Ray K
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13697 Visits: 4958
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!

+--------------------------------------------------------------------------------------+
‌Check out my blog at https://pianorayk.wordpress.com/
webrunner
webrunner
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16754 Visits: 4141
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

-------------------
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
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)

Group: General Forum Members
Points: 144269 Visits: 18651
I like the question. Nice job.

Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw
Learn Extended Events

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search