Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# NPER - (domain error occured)

Posted on 2004-10-21
Medium Priority
851 Views
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

Regards
TAZI

0
Question by:TAZI
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4
• 2

LVL 26

Accepted Solution

Hilaire earned 200 total points
ID: 12369506
TAZI, I'm afraid these values are simply not possible ....

Excel fails to get a value too with these parameters
0

LVL 1

Author Comment

ID: 12369588
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.

Regards
TAZI
0

LVL 26

Expert Comment

ID: 12369658
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

ID: 12369688
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

ID: 12369730
i meant "handle this case"
0

LVL 1

Author Comment

ID: 12370909
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.

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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backupâ€¦
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
###### Suggested Courses
Course of the Month9 days, 15 hours left to enroll