Click here to Skip to main content
15,905,967 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi

I was thinking the codes were correct because there as no more red lines. But when I run it, it shows this message:

Msg 8117, Level 16, State 1, Line 6<br />
Operand data type varchar is invalid for divide operator


Here is my query:
SQL
SELECT b.pnNumber
    ,b.loanAmount
    ,b.term
    ,((CAST(SUBSTRING(b.interestRate, PATINDEX('%[^0 ]%', b.interestRate + ' '), LEN(b.interestRate)) AS FLOAT) /100)/12) monthlyInterestRate
    ,POWER(((CAST(SUBSTRING(b.interestRate, PATINDEX('%[^0 ]%', b.interestRate + ' '), LEN(b.interestRate)) AS FLOAT) /100)/12), b.term) SuperScript
    ,CASE WHEN b.interestRate = 0 THEN b.loanAmount/b.term ELSE
        (b.loanAmount*((((CAST(SUBSTRING(b.interestRate, PATINDEX('%[^0 ]%', b.interestRate + ' '), LEN(b.interestRate)) AS FLOAT) /100)/12)*POWER(((CAST(SUBSTRING(b.interestRate, PATINDEX('%[^0 ]%', b.interestRate + ' '), LEN(b.interestRate)) AS FLOAT) /100)/12), b.term))-(POWER(((CAST(SUBSTRING(b.interestRate, PATINDEX('%[^0 ]%', b.interestRate + ' '), LEN(b.interestRate)) AS FLOAT) /100)/12), b.term)-1))) END MonthlyPayment
FROM vw_LoanMas_AcctRel AS b
WHERE b.billingBucket1 = 'U'


Thank you for helping me out in my problem.
Posted
Comments
Murugesan22 3-Jul-14 5:46am    
Please check with b.loanAmount/b.term datatypes
If any varchar datatype means you have convert to datatype which you want

What is the data type of b.term? I suspect its varchar. Please check
 
Share this answer
 
Your query contains, for instance, /b.term. If term is a varchar then you have to cast it to a number (if it makes sense) in order to use it as divide operand.
 
Share this answer
 
Comments
mitchiee1226 3-Jul-14 19:56pm    
I have done the cast of b.term to float and also b.loanAmount. The error gets worst.
Hi,

You have to check out that wherever you are using numerator and denominator all must be same data type i.e. Numeric data type.

Also, kindly make sure whether data exists in your table should not contain varchar data.

And whatever suggestion made above like use of CAST / CONVERT, if required use it.



Hope this will help you.

Cheers
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900