I am trying (so far unsucessfully) to use the @@error function to trap errors, record them and send the result set to me via email so I can "correct" the bad data in the specific rows.
My problem is, the email never gets sent and the rows that should be marked are not.
I'm sure it's something really simple that I'm missing, so please excuse my ignorance here.
Thanks in advance for your help on this issue.
Margaret
Code:
declare @error int
set @error =0
BEGIN TRANSACTION
insert into request_event select
externalrefid,
sequence,
security_code,
request_line,
req_line_sequence,
event_type,
event_type_reason,
event_dt,
event_tm,
customer_event_dt,
customer_event_tm,
person_id_from,
person_id_to,
description,
dur_minutes,
value_from,
value_to,
value_type,
promised_begin_dt,
promised_begin_tm
from
newevent2
where
chk=0
IF @@ERROR <>0 begin
set @error=2
end
IF @Error = 0 Begin
-- Update worked
Commit Tran
End
Else Begin
-- Error
update econupdate set chk=2
from econupdate join newwork on econupdate.externalrefid=newwork.externalrefid
and econupdate.econupdate_identity=newwork.updateindex
declare @query varchar (255)
set @query = 'select * from econupdate where chk=2'
exec master..xp_sendmail
@recipients='margaretn@ttc-inc.com',
@subject='Event insert step failed',
@query=@query,
@attach_results='true',
@width=250
Rollback Tran A
end
My problem is, the email never gets sent and the rows that should be marked are not.
I'm sure it's something really simple that I'm missing, so please excuse my ignorance here.
Thanks in advance for your help on this issue.
Margaret