Advertisement
Merry123

11. Calculating Interest

Jun 9th, 2023
1,433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.60 KB | None | 0 0
  1. CREATE FUNCTION `ufn_calculate_future_value`(`sum` DECIMAL(10, 4),
  2.                                             yearly_interest_rate DOUBLE,
  3.                                             number_of_years INT)
  4. RETURNS DECIMAL(10, 4)
  5. DETERMINISTIC
  6.  
  7. BEGIN
  8.     RETURN `sum` * (POW((1 + yearly_interest_rate), number_of_years));
  9. END;
  10.  
  11. CREATE PROCEDURE `usp_calculate_future_value_for_account`(account_id INT, interest_rate DOUBLE(19,4))
  12.  
  13. BEGIN
  14.  
  15.     SELECT a.id, ah.first_name, ah.last_name, a.balance,
  16.     `ufn_calculate_future_value`(a.balance, interest_rate, 5)
  17.     FROM accounts AS a
  18.     JOIN account_holders AS ah
  19.     ON a.account_holder_id = ah.id
  20.     WHERE a.id = account_id;
  21.  
  22. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement