Skip to content

Instantly share code, notes, and snippets.

@bpdarlyn
Created October 21, 2016 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpdarlyn/1d994a004e9f7a83d8676be4201c4599 to your computer and use it in GitHub Desktop.
Save bpdarlyn/1d994a004e9f7a83d8676be4201c4599 to your computer and use it in GitHub Desktop.
DELIMITER //
create procedure darlyn(in _pay int)
begin
declare _per integer;
declare _cap decimal(12,4);
declare _fee decimal (12,4);
declare _pcb decimal (12,4);
declare _pb decimal (12,4);
declare cur1 cursor for
select period, capital, fee_period, principal_capital_balance, principal_balance
from fee_contract_period where payment_plan_id = _pay order by period and period > 1;
declare continue handler for not found set done = true;
open cur1;
read_loop: loop
fetch cur1 into _per, _cap, _fee, _pcb, _pb;
update fee_contract_periods
set principal_capital_balance = _pcb - capital,
principal_balance = _pb - fee_period
where payment_plan_id = _pay and period = _per + 1;
end loop;
close cur1;
end
//
DELIMITER ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment