I have the following code (which is not mine and found on a website which that person did a great job with this)This code does exactly what I need except I am still a newbie and don't understand how I can pass multiple loans through it. I have tried several ways to insert the set command for each declaration and each time I get errors. Any help would be appreciative.
\-------Section I think my table values go in-------
I am updating this section in response to the answer given. So the Fiddle does what I need the way you have it setup but my only issue is I have read only access for reporting and running sql scripts for data. I can not create function to pass through. Sorry I should have mentioned that. My other issue it that all my loans will be based on 12 months period with varying total months. Sample table data below:
| LoanNumber | LoanStart | LoanEnd | LoanAmount | YrlyInt | LoanMonths |
|---|---|---|---|---|---|
| 11111 | 07/10/2023 | 07/06/2027 | 11341.98 | 6.65 | 48 |
| 22222 | 03/03/2022 | 02/25/2027 | 11242.78 | 3.25 | 60 |
| 33333 | 07/22/2020 | 07/25/2024 | 10496.91 | 3.43 | 48 |
I couldn't figure out the logic of how to make it a static period and then use my loanmonths for the actual calculations. SQL fiddle does it right but when I try to change it to my table data that is where it goes buggy.
How it should be:
How mine is: enter image description here
[enter image description here][3]
[enter image description here][4]
[enter image description here][5]
Desired Output here. [3]: https://i.stack.imgur.com/J3j6D.png [4]: https://i.stack.imgur.com/bg32u.png [5]: https://i.stack.imgur.com/BQSHh.png
See example.
Loans:
Function
Use of function
Output
Example fiddle
See another example, where stored procedure converted to query
Fiddle
There we can put parameters for query from table as
Or parameters can be external