Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

data type conversion

Status
Not open for further replies.

rds80

Programmer
Nov 2, 2006
124
0
0
US
NS.Numerator is of type money,
I'm using that field in a select statement, but the error: Error converting data type varchar to numeric. comes up. So I tried this CONVERT(money, CONVERT(varchar, NS.Numerator)), but still get the error.

Please help. Thanks.
 
Can you show us your select statement?

-SQLBill

Posting advice: FAQ481-4875
 
ACC is of type money. The value in CM.ACC is .0000.

I expect
Code:
CASE WHEN CM.ACC IS NULL OR CM.ACC  = 0 THEN ''
ELSE CONVERT(varchar, (LA.Numerator/CM.ACC)) * 100 END

to show a blank cell. However, the cell has the value .0000

Is this because sql interprets 0 differently then .0000?

Thanks.


 
CM.ACC is the denominator. Checking for 0 is good to prevent divide by zero errors. However, if LA.Numerator is 0 (and knowing that 0 divided by any number is always 0), you will still get a 0.

So... Do you have any 0's in the LA table?

Select * From LA Where Numerator = 0



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
No 0s.
My co-worker helped me with the problem. It should have been:

Code:
CASE WHEN CM.ACC IS NULL OR CM.ACC  = 0 THEN ''
ELSE CONVERT(varchar, (LA.Numerator/CM.ACC) * 100) END

Parantheses were in the wrong place.
 
Yes, and what was happening was you were converting and then trying to multiply the VARCHAR result by 100. That didn't work. Once you fixed the parenthesis, you did all the math, then converted the results to VARCHAR.

That's why it's good to supply the code.

-SQLBill

Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top