CREATE PROCEDURE [dbo].[usp_run_daily_refresh] ASDECLARE @Error_int Int, @Err_Msg_vchr varchar(255), @Parameters_vchr varchar(255), @SP_Name_vchr varchar(30), @Ref_Table_Name_vchr varchar(30), @Error_Notes_vchr varchar(255), @ParmDefinition_nvchr VARCHAR(50) BEGIN TRANEXECUTE usp_emp_detail_u SELECT @Error_int=@@error IF @Error_int > 0 BEGIN SET @SP_Name_vchr='usp_emp_detail_u' SET @Ref_Table_Name_vchr='emp_detail' GOTO Error_handler ROLLBACK TRANENDEXECUTE usp_emp_referral_detail_uSELECT @Error_int=@@error IF @Error_int > 0 BEGIN SET @SP_Name_vchr='usp_emp_referral_detail_u' SET @Ref_Table_Name_vchr=emp_referral_detail' GOTO Error_handler ROLLBACK TRANENDEXECUTE usp_emp_status_detail_uSELECT @Error_int=@@error IF @Error_int > 0 BEGIN SET @SP_Name_vchr='usp_emp_status_detail_u' SET @Ref_Table_Name_vchr='emp_status_detail' GOTO Error_handler ROLLBACK TRANENDEXECUTE usp_corp_company_detail_u SELECT @Error_int=@@error IF @Error_int > 0 BEGIN SET @SP_Name_vchr='usp_corp_company_detail_u' SET @Ref_Table_Name_vchr='corp_company_detail' GOTO Error_handler ROLLBACK TRANENDEXECUTE usp_bank_info_uSELECT @Error_int=@@error IF @Error_int > 0 BEGIN SET @SP_Name_vchr='usp_bank_info_u' SET @Ref_Table_Name_vchr='bank_info' GOTO Error_handler ROLLBACK TRANENDCOMMIT TRANSET @Error_Int = @@ErrorError_handler:If (@error_Int <> 0 ) BEGIN IF (@FromDal='N') BEGIN SET @Parameters_vchr = 'None' SET @Err_Msg_vchr =(SELECT Description FROM master..sysmessages WHERE error = @Error_int) EXEC usp_MrErrorHandler @ErrorNo = @Error_int, @ErrorMsg = @Err_Msg_vchr, @TableName = @Ref_Table_Name_vchr, @CallingSPName = @SP_Name_vchr, @Parameters = @Parameters_vchr, @ErrorNotes = @Error_Notes_vchr RETURN @Error_int END ELSE BEGIN RETURN @Error_int END ENDELSE BEGIN RETURN 0 ENDEND
Here the usp_run_daily_refresh stored procedure calls multiple stored procedures inside.If one fails it should rollback the full transaction.Is this the correct way to capture the error or should I use something likeSET @Error_int=EXECUTE usp_bank_info_u IF @Error_int > 0 BEGIN SET @SP_Name_vchr='usp_bank_info_u' SET @Ref_Table_Name_vchr='bank_info' GOTO Error_handler ROLLBACK TRANENDfor all the store procedures