Solved

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

Posted on 2009-05-19
10
339 Views
Last Modified: 2013-12-25
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?
0
Comment
Question by:jrking1978
  • 4
  • 3
  • 3
10 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24426806
what if you do:
select qty, price, qty * price result from table1 
then in ASP:
<%=rs("result")%>

Open in new window

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24427734
>>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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24427735
Ah, never mind.  I misread.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jrking1978
ID: 24484078
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24484139
ok, what if you do like this:
<%=cdbl(rs("qty").value)*cdbl(rs("price").value)%>

Open in new window

0
 

Author Comment

by:jrking1978
ID: 24484471
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24485910
>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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24485957
If we had the values for rs("qty") and rs("price") we may be able to do better then guess.
0
 

Accepted Solution

by:
jrking1978 earned 0 total points
ID: 24486000
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24488697
If rs("qty") and rs("price") are not null then I am afraid I have no idea.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

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…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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.

679 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