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
329 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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
>>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
Comment Utility
Ah, never mind.  I misread.
0
 

Author Comment

by:jrking1978
Comment Utility
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 142

Expert Comment

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

Open in new window

0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:jrking1978
Comment Utility
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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
>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
Comment Utility
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
Comment Utility
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
Comment Utility
If rs("qty") and rs("price") are not null then I am afraid I have no idea.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now