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
336 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]
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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 142

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 142

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

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 extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

770 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