SQL query with Loop to calculate interest on customer payments made during the month

  • I need to write a SQL script that will take a sales transaction and then look at the payments during a specific time and calculate interest payable from the due date up to each payment date.

    There are no set number/ quantity of payments during the month, so the script will have to loop through all the payments made and arrive at an exit point with interest calculations at each payment point.

    Any ideas to assist?:crying:

  • Looks like a variation on the running totals. I'd recommend two things; the first read the second article in my signature block, and two is use a properly constructed temporary table in you solution.

    Beyond that, if you want a better answer, read the first article in my signature block below.

  • There was a very similar thread to this a little while back. You might care to do a search using the SSC google search box (top right on most pages). I ended up posting working calculations for the interest portions (based on the Excel functions) depending on the parameters.

    It can be done with the running totals solution (like Lynn pointed out).

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Matt Miller (11/24/2008)


    There was a very similar thread to this a little while back. You might care to do a search using the SSC google search box (top right on most pages). I ended up posting working calculations for the interest portions (based on the Excel functions) depending on the parameters.

    It can be done with the running totals solution (like Lynn pointed out).

    Sounds familiar. Didn't I make a similiar recommendation in that thread also about running totals??

  • Lynn Pettis (11/24/2008)


    Matt Miller (11/24/2008)


    There was a very similar thread to this a little while back. You might care to do a search using the SSC google search box (top right on most pages). I ended up posting working calculations for the interest portions (based on the Excel functions) depending on the parameters.

    It can be done with the running totals solution (like Lynn pointed out).

    Sounds familiar. Didn't I make a similiar recommendation in that thread also about running totals??

    If my memory serves - yup...:)

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Slowly wading my way through the suggested reading, thanks.....

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply