IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[CP_Contratos_SP1]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[CP_Contratos_SP1] 
END
GO


CREATE PROCEDURE dbo.CP_Contratos_SP1 
@Id_Contrato	INT
AS 

DECLARE @Mensaje		VARCHAR(100)
DECLARE @ErrorLine		INT
DECLARE @ErrorNumber	INT

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[CP_Contratos_SP1_]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
	EXEC CP_Contratos_SP1_ @Id_Contrato
	SELECT	 @ErrorNumber	AS ErrorNumber 
			,0				AS ErrorSeverity  
			,0				AS ErrorState 
			,0				AS ErrorProcedure  
			,@ErrorLine		AS ErrorLine		
			,@Mensaje		AS ErrorMessage
	RETURN
END				   


BEGIN TRY
	BEGIN TRAN

	/* Utilizar @ErrorNumber para devolver ids, por ejemplo el id_trans o id_contrato */

	SET @ErrorNumber	= 99
	SET @Mensaje		= 'Procedimiento no configurado (CP_Contratos_SP1).'
	SET @ErrorLine		= 0

	/*En caso de salida exitosa la devolucion deberia ser la siguiente*/
	/*
	SET @ErrorNumber	= 0
	SET @Mensaje		= 'Renovación Exitosa'
	SET @ErrorLine		= @Id_Contrato_Nuevo
	*/



    COMMIT
	SELECT	 @ErrorNumber	AS ErrorNumber 
			,0				AS ErrorSeverity  
			,0				AS ErrorState 
			,0				AS ErrorProcedure  
			,@ErrorLine		AS ErrorLine		
			,@Mensaje		AS ErrorMessage

END TRY  


BEGIN CATCH  
    EXECUTE usp_GetErrorInfo;  
	ROLLBACK
END CATCH;   
