with T1 as
(
----------------------------------------
select row_number() over(order by FHCHA) as SORT,FHCHA,DESCRIPCION,EGRESO,INGRESO,BALANCE,sum(BALANCE-EGRESO+INGRESO) as ALL_BALANCE,BankID
FROM (
SELECT FHCHA,'BALANCE' as DESCRIPCION,0 as EGRESO,0 as INGRESO, BALANCE,BankID FROM Bms_BankAccountBalance
union
SELECT ReceiptsDate,Notes,0, Amount ,0,BankID from Bms_CustomerReceipts
union
SELECT PaymentDate,Notes ,TotalAmount ,0,0,BankID from Bms_SupPayment
) T group by FHCHA,DESCRIPCION,EGRESO,INGRESO,BALANCE,BankID
-----------------------------------------------
)
select *,Cumulation=(select SUM(ALL_BALANCE) from T1 T_In
where T_In.BankID=T_Out.BankID and T_In.SORT<=T_Out.SORT)
from T1 T_Out