Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the error message

Status
Not open for further replies.

carlavieira

Programmer
Aug 30, 2002
8
0
0
BR
I have a procedure that will be executed by job or query analyzer. Within I have an insert:

insert tab1 (cp1,cp2)
values (@cp1,@cp2)

IF (@@error <> 0)
begin
goto grava_erro
end
.
.
.
grava_erro:
select @msg_erro = description from sysmessage where error = @@error

insert tab_erro (erro, dt, cp1, cp2)
values (@msg_erro, getdate(), @cp1,@cp2)


Is there another way to get the error message?


Thank you


Carla (carla.vieira@consist.com.br)
 
Hi,

Replace SYSMESSAGE with MASTER.DBO.SYSMESSAGES

Because @@ERROR is cleared and reset on each statement executed, check it immediately following the statement being validated or save it to a local variable that can be checked later.

(1) Select statement or INSERT statement or UPDATE statement
(2) SELECT @ErrorNumber=@@ERROR
(3) Use @ErrorNumber for any error handling or to control the flow of code.

Hope it hepls.

Sreenivas
avnsr@hotmail.com
-----------------


Hope it helps.

Sreenivas
avnsr@hotmail.com
-----------------
 
Thanks Sreenivas,

But what about that kind of message which has variable in it. This variable will be replaced by the column or other information?

Regards,
Carla
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top