I have a problem. Actually in our application, earlier the customer was allowed to pay 3 installemnt per month but now it can be any number . So I have the earlier query
Row by row, you can't change the number of output columns.
If I understand correctly, you'll have to build it for the maximum number of columns and give NULL/0 for unused columns.
Edit: which is what Andomar is doing but he dynamically chooses the maximum number of columns