[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
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
Medium Priority
?
355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 ?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

650 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