In addition to Solution 1 ...
You have not described your logic and it is not clear what your logic is to get to those figures.
You seem to
- switch between a 30 day month and a calendar month (I am assuming that EMI is the amount to accumulate each month / 30 days)
- switch between applying the figures to the beginning of the range then to the middle (by the methods I tried 137800 is reached in month 24 (or 25 depending on my first point) and not month 13 nor 36
- be inconsistent in your ranges 6-12 months is followed by 13-36 months, but then that is followed by 36-60 months
Quote:Dont have much clue to start with store procedure or function
Don't start with either!
Start by working out how you are going to get those numbers (or the correct numbers)
Now some suggestions on how you might start to code it up
- You will need a lists of Dates (often called a Dimension Table - here is an example Creating a Date Dimension Table - Overview, Importance, Methods
] (Warning - pop up offering free courses, ignore and dismiss it)
- You will probably want to have a cross join between that table and your data table (see Cross Join Introduction – Create Row Combinations
- To get the data in the format you need you will need to know about Pivot Simple Way To Use Pivot In SQL Query
] and GROUP BY (Transact-SQL) - SQL Server | Microsoft Docs