计算利息随时间推移的金额SQL Server 2012

时间:2019-02-25 22:40:12

标签: sql-server-2012

Initial Amount = $100
Interest Rate = 5%
Number of years = 3

总金额= $ 115.76

我将如何在Sql Server中计算这个?

1 个答案:

答案 0 :(得分:1)

这是我计算总金额的方法:

DECLARE @Current_LeaseEndDate DATE = '01/31/2021'  --3 Years
DECLARE @PercentIncrease  FLOAT = .05
DECLARE @Principal FLOAT = 100

SELECT 
YEAR(DATEADD(day, 1, CAST(@Current_LeaseEndDate AS VARCHAR(10))) + 1),
CASE WHEN YEAR(DATEADD(day, 1, CAST(@Current_LeaseEndDate AS VARCHAR(10))) + 1) >= YEAR(GETDATE())
        THEN @Principal * POWER((1 + @PercentIncrease), YEAR(DATEADD(day, 1, CAST(@Current_LeaseEndDate AS VARCHAR(10))) + 1) - YEAR(GETDATE()))
        END AS MEH