I have a single “Pre-Processing” Stored procedure which calls multiple stored procedures inside.
Finally when all my SPS (inside) have successfully executed, I want to run an update statment, so in the main SP I have :
EXEC SP1
EXEC SP2
EXEC SP3
-- RUN UPDATE statment here
All of my inner SPs have the following template :
BEGIN TRY
BEGIN TRANSACTION
// DO SOME INSERT,UPDATE ETC..
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber
,ERROR_SEVERITY() AS ErrorSeverity
,ERROR_STATE() AS ErrorState
,ERROR_PROCEDURE() AS ErrorProcedure
,ERROR_LINE() AS ErrorLine
,ERROR_MESSAGE() AS ErrorMessage;
IF @@TRANCOUNT > 0
ROLLBACK TRANSACTION;
RETURN
END CATCH
My question is as to what is the best approach for error handling in this scenario, i.e. I want to make sure everything got done before I run that final update statement.
Closing this since I figured out that each SP had to have its own Error handling and the outside SP calling multiple SPs would not need to have error handling.