DROP PROC CARGA_TRANHIST_PROC
GO
CREATE PROC CARGA_TRANHIST_PROC
AS
BEGIN
	BEGIN TRAN

		INSERT 	INTO OP_HISTRANSFUEL
			SELECT * FROM OP_TRAN
		
		IF(@@ERROR!=0)
		BEGIN 
			RAISERROR 20000 'Error Cargando Historico de TRAN'
			ROLLBACK
			RETURN(1)
		END

		DELETE FROM OP_TRAN

		IF(@@ERROR!=0)
		BEGIN 
			RAISERROR 20000 'Error Eliminando registros de OP_TRAN'
			ROLLBACK
			RETURN(1)
		END
	

	COMMIT TRAN
	RETURN(0)
END 
