What is Meant By @@Error??????????????

Posted by Sabarimahesh under Sql Server on 4/10/2012 | Points: 10 | Views : 1303 | Status : [Member] | Replies : 8
@@Error

What is @@Error??

What is the use????

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M



Responses

Posted by: Pandians on: 4/10/2012 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi

@@Error: It returns the Last occurred Error number
For further reading: http://msdn.microsoft.com/en-us/library/aa933181%28v=sql.80%29.aspx
Begin Try 

Select 1/0
End Try
Begin Catch
Select [Text] [Error Message] From Sys.messages Where message_id =@@Error And language_id = 1033
End Catch
You can use the following Structured exception handling functions instead in SQL Server 2005 onwards...
ERROR_NUMBER()
ERROR_MESSAGE()
ERROR_SEVERITY()
ERROR_STATE()
ERROR_LINE()
ERROR_PROCEDURE()

User: When mapping a "Login" with the "Database" - created under database called "User"

- User is a Database specific and Login is Server or Instance specific.

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Sabarimahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 4/10/2012 [Member] Bronze | Points: 25

Up
0
Down
Pandians
Ho!!!!!!!! Thanks

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Sabarimahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 6/19/2012 [Member] Bronze | Points: 25

Up
0
Down

@@Error is a Global variable.
It returns the information about the return value of the last executed transact-SQL statement

Sabarimahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jasminej on: 6/19/2012 [Member] Starter | Points: 25

Up
0
Down
@Muhsinathk

Do you think, the statement what you have posted is correct ?

Are you sure, @@Error returns the last occurred Error status/code (or) last executed TSQL statement ?

Kindly check!

thank you

Sabarimahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 6/20/2012 [Member] Silver | Points: 25

Up
0
Down
We can consider @@ERROR as one of the basic error handling mechanisms in SQL Server.
@@ERROR returns an error number if the previous statement encountered an error.
Returns 0 if the previous Transact-SQL statement encountered no errors.
Because @@ERROR is cleared and reset on each statement executed, check it immediately
following the statement being verified, or save it to a local variable that can be checked later.

Source:-MSDN http://msdn.microsoft.com/en-us/library/ms188790.aspx

More to read http://www.codeproject.com/Articles/38650/Overview-of-Error-Handling-in-SQL-Server-2005

Sabarimahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 7/31/2012 [Member] Silver | Points: 25

Up
0
Down
please mark it as answer....That helps other who search the same...

Sabarimahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vimalrnsin-17147 on: 7/31/2012 [Member] Starter | Points: 25

Up
0
Down
We can consider @@ERROR as one of the basic error handling mechanisms in SQL Server.
@@ERROR returns an error number if the previous statement encountered an error.
Returns 0 if the previous Transact-SQL statement encountered no errors.
Because @@ERROR is cleared and reset on each statement executed, check it immediately
following the statement being verified, or save it to a local variable that can be checked later.


Are you sure, @@Error returns the last occurred Error status/code (or) last executed TSQL statement ?

Sabarimahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vimalrnsin-17147 on: 7/31/2012 [Member] Starter | Points: 25

Up
0
Down
hi

Sabarimahesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response