473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Query results in needless/extra zeros

I have a datasheet subform that is based off an ADO recordset. All is
fine excpet the query results are displayed oddly. Rather than
displaying the results as say 95.43, it displays it as
95.430000000000000. Obviously I don't want these extra zero's. I have
tried limiting the decimal places in the properties of the textbox in
which the results are displayed, but no effect. Hopefully one of you
have an idea. Thanks for your help!
-Jeremy

Nov 13 '05 #1
6 1768
"Jeremy" <sl********@hotmail.com> wrote in message news:11**********************@z14g2000cwz.googlegr oups.com...
I have a datasheet subform that is based off an ADO recordset. All is
fine excpet the query results are displayed oddly. Rather than
displaying the results as say 95.43, it displays it as
95.430000000000000. Obviously I don't want these extra zero's. I have
tried limiting the decimal places in the properties of the textbox in
which the results are displayed, but no effect. Hopefully one of you
have an idea. Thanks for your help!

format([myfield], "#.00")
Nov 13 '05 #2
Thanks for the response Wind, but I have tried that and no effect. I
think it has something to do with the SQL query as I am using "Cast (my
query/calculation) as Decimal". Which I have to do to get the query to
work. For example:

strSQL = strSQL & " ROUND((CAST(COUNT(CASE WHEN VINInputSource = 'V'
THEN 1 ELSE NULL END) as decimal)/Cast(COUNT(CASE WHEN VINInputSource
Is NOT NULL THEN 1 ELSE NULL END) as Decimal)*100),2) VINScan,"
etc, etc...

The sql statements that do not use "Cast...As Decimal" will format
fine. Any ideas?

Nov 13 '05 #3

"Jeremy" <sl********@hotmail.com> wrote in message news:11**********************@z14g2000cwz.googlegr oups.com...
Thanks for the response Wind, but I have tried that and no effect. I
think it has something to do with the SQL query as I am using "Cast (my
query/calculation) as Decimal". Which I have to do to get the query to
work. For example:

strSQL = strSQL & " ROUND((CAST(COUNT(CASE WHEN VINInputSource = 'V'
THEN 1 ELSE NULL END) as decimal)/Cast(COUNT(CASE WHEN VINInputSource
Is NOT NULL THEN 1 ELSE NULL END) as Decimal)*100),2) VINScan,"
etc, etc...

The sql statements that do not use "Cast...As Decimal" will format
fine. Any ideas?


I have never heard of cast ... what does that do?
Nov 13 '05 #4

"Jeremy" <sl********@hotmail.com> wrote in message news:11**********************@z14g2000cwz.googlegr oups.com...
Thanks for the response Wind, but I have tried that and no effect. I
think it has something to do with the SQL query as I am using "Cast (my
query/calculation) as Decimal". Which I have to do to get the query to
work. For example:

strSQL = strSQL & " ROUND((CAST(COUNT(CASE WHEN VINInputSource = 'V'
THEN 1 ELSE NULL END) as decimal)/Cast(COUNT(CASE WHEN VINInputSource
Is NOT NULL THEN 1 ELSE NULL END) as Decimal)*100),2) VINScan,"
etc, etc...

The sql statements that do not use "Cast...As Decimal" will format
fine. Any ideas?


It is always really useful to break it down into many little steps and check each step along the way... rather than having one long
statement. Maybe Cast is fine, but the content is wrong, maybe Cast does not work itself...
Nov 13 '05 #5
I still haven't figured this one out....

As to your question, CAST is a SQL command that converts data from one
type to another, in this case I am converting an integer to a decimal
so that I can get a percentage. It is similar to VB commands like
CBool, CDate, CInt, etc... Simply converting from one data type to
another. I just don't understand why Access, or ADO in this case,
returns tons of needless zero's.

I have tried eliminating the CAST command and WALLAH! It works, no
extra zero's. But then I get a whole number and don't get the two
decimal places nessecary to form a percentage.

Nov 13 '05 #6

"Jeremy" <sl********@hotmail.com> wrote in message news:11**********************@l41g2000cwc.googlegr oups.com...
I still haven't figured this one out....

As to your question, CAST is a SQL command that converts data from one
type to another, in this case I am converting an integer to a decimal
so that I can get a percentage. It is similar to VB commands like
CBool, CDate, CInt, etc... Simply converting from one data type to
another. I just don't understand why Access, or ADO in this case,
returns tons of needless zero's.

I have tried eliminating the CAST command and WALLAH! It works, no
extra zero's. But then I get a whole number and don't get the two
decimal places nessecary to form a percentage.


I think it may be a rounding issue on conversion (guess). I would just enclose the whole thing in format(#.00) or times it by one
hundred and then divide it again.

Anyway, I would not use SQL to convert numbers, I would do that in Access itself, as you will have more control over it.

In this situation I would be practical rather than theoretical.

HTH

- Nicolaas
Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DBNovice | last post by:
I have a database that keeps records on the issue and failure of an item. Currently, the database is poorly desisned; therefore I'm performing queries to break the data into normalized tables and...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
1
by: dharper | last post by:
I have a table that seems to have a bad index. When I do the following query I get inconsistant and needless to say incorrect results. select count(*) from mytable where mycolumn = 1 If I...
1
by: John Smith | last post by:
I've been too far away from SQL for too long doing other-level things and my ancient addled brain isn't what it once was. Here's the deal: My wife is doing a small app in Access. I know zippo...
12
by: Larry Bates | last post by:
I'm trying to get the results of binascii.crc32 to match the results of another utility that produces 32 bit unsigned CRCs. binascii.crc32 returns results in the range of -2**31-1 and 2**21-1....
24
by: clare at snyder.on.ca | last post by:
I have a SQL query I need to design to select name and email addresses for policies that are due and not renewed in a given time period. The problem is, the database keeps the information for every...
2
by: AJ | last post by:
Hi all, I have this monster query (at least i think it is). SELECT c.ID, c.Company_Name, p., 1 As QueryNbr FROM (Company AS c LEFT JOIN Sale AS s ON c.ID = s.Company_ID) LEFT JOIN Package...
11
by: Bruce Lawrence | last post by:
Ok, I'm baffled... I'm making a query in access 97 between 2 tables. There is a field in both tables called "DWGNO". OPENORD has a record with a DWGNO of "00000012345" DIEDATA has a record...
10
kcdoell
by: kcdoell | last post by:
I have a listbox on a form that uses my crosstab query to display the query results. For the fields that display numbers, the numbers with a zero in the last digit are being dropped. Example $88.80...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.