Why am I getting a 800a000d in ASP when pulling from a db decimal/numeric and doing math

This is a SQL 2000 server

table1 looks like this:
qty   (decimal, precision:18, scale: 2)
price  (decimal, precision:18, scale: 2)

I open a record set:
select * from table1

then in ASP:
<%=rs("qty")*rs("price")%>

I get a type mismatch error. If I change the fields to float, it calculates fine. Can't I use decimal or numeric, and not have to do any conversions?
jrking1978Asked:
Who is Participating?
 
jrking1978Connect With a Mentor Author Commented:
rs(qty) 1
rs(price) 100
I just setup a table to test it, it doesn't matter what values I put in there, I get an error. But if I use float, or money errors go away. Its more of a curiosity question. If you do not know, thats fine, it just was bugging me, and I thought somone could tell me if it was somthing I was doing (in setting the filed in sql) or if it was a bug.

thanks!
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
what if you do:
select qty, price, qty * price result from table1 
then in ASP:
<%=rs("result")%>

Open in new window

0
 
Anthony PerkinsCommented:
>>Can't I use decimal or numeric, and not have to do any conversions?<<
Yes, you can.  Unfortunately until you set the Precision and NumericScale properties in ADO you will continue to get that error.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Anthony PerkinsCommented:
Ah, never mind.  I misread.
0
 
jrking1978Author Commented:
I know I can do caluculations in SQL, but I am wondering why it is not working for my example above. If no ones knows, thats fine.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
ok, what if you do like this:
<%=cdbl(rs("qty").value)*cdbl(rs("price").value)%>

Open in new window

0
 
jrking1978Author Commented:
That will work to, but my question is why, when I have set it in sql as decimal or numeric, do I have to still convert it again. This does not happen when I use money, or float. But only decimal or numeric.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>do I have to still convert it again.
I cannot answer the "why" for sure.
i have to presume that asp code, as it is loosely data typed, seeing the * between 2 objects (rs("qty") is an object (adodb.field), and NOT a decimal), it has to "guess" about the data types capacity.
and in your case, it guesses wrong.
with cdbl(), you tell the code instead of guessing.
0
 
Anthony PerkinsCommented:
If we had the values for rs("qty") and rs("price") we may be able to do better then guess.
0
 
Anthony PerkinsCommented:
If rs("qty") and rs("price") are not null then I am afraid I have no idea.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.