Solved

NPER - (domain error occured)

Posted on 2004-10-21
835 Views
Last Modified: 2008-01-09
Hi

Hilare assisted with the creation of a NPER Function that works similar to excel.  

This is the NPER Function

create function NPERTEST(@rate float, @payment float,@capital float)
returns float
as
begin
return log10(@payment/(@payment+@capital*@rate))/log10(1+@rate)
end
go

select dbo.NPER(.203/12, 500, -5000)  ---> returns 11.047592792208778

This works well and I haven't noticed a problem until this morning.  Based on the value of the payment the procedure throws out a domain error occurred

Try this

Select dbo.NPERTEST(.203/12, 75, -5000) - Payment amount is R 75

Your urgent assistance is required

Thanks for your help in advance

Regards
TAZI

0
Question by:TAZI
    6 Comments
     
    LVL 26

    Accepted Solution

    by:
    TAZI, I'm afraid these values are simply not possible ....

    Excel fails to get a value too with these parameters
    it gives #number instead of a readable value
    0
     
    LVL 1

    Author Comment

    by:TAZI
    Hi Hilare

    Thanks a million for your prompt response.

    How would this be handled then.  I didn't test it in Excel, but have been bothered by it all morning.

    Basically, the procedure is being used in an Debt Collection Environment. In the example above, the Debtor owes R5000.00 and the interest rate is 20.3%.  If the debtor wants to pay  R 75.00 per month, how would we determine the number of periods then.

    The payment amount is dynamic ... one does not know how much the debtor wants to pay.

    Thanks for your help in advance
    Regards
    TAZI
    0
     
    LVL 26

    Expert Comment

    by:Hilaire
    when (@payment+(@capital*@rate)) is negative,
    log10(@payment+(@capital*@rate)) can't be computed
    using microsoft's algorithm ...

    best I can do is return a default value (eg 0) when a correct NPER can't be computed

    create function NPERTEST(@rate float, @payment float,@capital float)
    returns float
    as
    begin
    return case  
                   when @payment+@capital*@rate < 0 then 0
                   else log10(@payment/(@payment+@capital*@rate))/log10(1+@rate)
             end
    end
    go
    0
     
    LVL 26

    Expert Comment

    by:Hilaire
    Yet a default value of 0 might generate more errors if you use this NPER in other calculations,
    so maybe another dummy value like 9999999 would be better.

    Anyway you'll have to handle this care somewhere in your code and alert the user on the fact that NPER can't be computed with these parameters values
    0
     
    LVL 26

    Expert Comment

    by:Hilaire
    i meant "handle this case"
    0
     
    LVL 1

    Author Comment

    by:TAZI
    Hi Hilare

    Thank you so much for your help.  

    I did the following to overcome the problem. I work out the minimum payment that a debtor can make against his outstanding debt and if the amount that the debtor wants to pay is less then mimimum payment  I know I am going to get an error and return out of the procedure with the minimum value.  I then display this on screen informing the collector that he/she has to capture a value greater then the minimum payment.

    Thanks anyway for your help.

    It is greately appreciate.

    I will assign the 50 points to you .. you deserve it with all the help that you've given me with these procedures.

    Thanks
    Regards
    TAZI
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    This is my first ever Article on EE or elsewhere; therefore, please bear with me if I have some discrepancies in my writing. I read many articles and questions related to "how to pass values to SSIS packages at run-time?"  Hence, this common ques…
    Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
    Via a live example, show how to shrink a transaction log file down to a reasonable size.

    846 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now