hristocr

Untitled

Oct 16th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. CREATE FUNCTION ufn_calculate_future_value (sum DECIMAL(38,18),interest DECIMAL(38,18), years INT)
  2. RETURNS DECIMAL(38,18)
  3. BEGIN
  4. DECLARE result DECIMAL (38,18);
  5. SET result := sum * pow(1 + interest,years);
  6. RETURN result;
  7. END;
  8.  
  9. CREATE PROCEDURE usp_calculate_future_value_for_account (account_id INT, interest_rate DECIMAL(13,4))
  10. BEGIN
  11. SELECT account_id,
  12. ah.first_name,
  13. ah.last_name,
  14. a.balance AS 'current_balance',
  15. round(ufn_calculate_future_value(a.balance,interest_rate,5),4)
  16. AS 'balance_in_5_years'
  17. FROM account_holders ah
  18. JOIN accounts a ON ah.id = a.account_holder_id
  19. WHERE a.id=account_id;
  20. END;
Advertisement
Add Comment
Please, Sign In to add comment