trpnbillie
Programmer
Hi All! I bet I can stump ya!
I have a trigger on a table and the trigger calls a stored procedure. I would like to capture errors in the stored procedure but for some reason, SQL Server will not continue commands after the error - it simply stops and hence, I cannot capture/raiserror.
What is strange is that if I cut and paste the stored procedure and run it manually in Query Analyzer, it WILL continue commands and I AM able to capture, raiserror.
Here is what I call:
-------
DECLARE @MN as varchar(20), @ID as Int
SELECT @ID = 200
SELECT @MN = master_number from Imp_TestTable where Record_ID = @ID
BEGIN TRANSACTION
UPDATE A_TestTable2
SET [master number] = @MN, [field1] = 'too long'
WHERE [master number] = @MN
/* the above update statement is designed to fail */
IF @@ERROR <> 0
BEGIN
RAISERROR('this sucks', 18,1)
END
ELSE
COMMIT TRANSACTION
GO
--------
It's so strange that it will work in Query Analyzer but not in a sproc called by a trigger.
Is it illegal to call sprocs and capture errors from a trigger?
Any help is greatly appreciated!! Thank you so much!
I have a trigger on a table and the trigger calls a stored procedure. I would like to capture errors in the stored procedure but for some reason, SQL Server will not continue commands after the error - it simply stops and hence, I cannot capture/raiserror.
What is strange is that if I cut and paste the stored procedure and run it manually in Query Analyzer, it WILL continue commands and I AM able to capture, raiserror.
Here is what I call:
-------
DECLARE @MN as varchar(20), @ID as Int
SELECT @ID = 200
SELECT @MN = master_number from Imp_TestTable where Record_ID = @ID
BEGIN TRANSACTION
UPDATE A_TestTable2
SET [master number] = @MN, [field1] = 'too long'
WHERE [master number] = @MN
/* the above update statement is designed to fail */
IF @@ERROR <> 0
BEGIN
RAISERROR('this sucks', 18,1)
END
ELSE
COMMIT TRANSACTION
GO
--------
It's so strange that it will work in Query Analyzer but not in a sproc called by a trigger.
Is it illegal to call sprocs and capture errors from a trigger?
Any help is greatly appreciated!! Thank you so much!