473,378 Members | 1,140 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,378 software developers and data experts.

SQL: Comparing Two Double Fields, Getting False Diffs?

I'm equi-joining two tables on a Long and a DateTime field and then
comparing an amount in one with an amount the other via an Immediate If
statement.

Problem is that for some (not all...not even most...) records, I am getting
false differences.

I know the stuff below probably looks like a rat's breakfast, but I'm at the end
of my little string on this. Similar things are happening in a couple other
queries, so I'd have to assume it's something dumb that I'm doing...but I can't
figure out what.

If anybody's got time on their hands and/or some excess curiosity, I could email
you the sample DB - it's only 9k zipped.

This is about as far down as I can pare down the SQL:
--------------------------------
SELECT
Table1.RecordID1,
Table2.RecordID2,
Table1.FundID,
Table1.Amount1,
Table2.Amount2,
IIf([Table2].[Amount2]<>[Table1].[Amount1],True,False) AS AmountsDiffer,
Table2.IsChosen

FROM
Table1 INNER JOIN Table2 ON (Table1.FundID = Table2.FundID) AND
(Table1.ReturnDate = Table2.ReturnDate)

WHERE
(((IIf([Table2].[Amount2]<>[Table1].[Amount1],True,False))=True) AND
((Table2.IsChosen)=False));
--------------------------------

FundID's are Long, ReturnDates are DateTime.
Amounts are Double.

Table1's Data:
--------------------------------------------
FundID ReturnDate Amount1 RecordID1
1588 09/01/1991 0.0624 1
1588 12/01/1991 0.0618 2
--------------------------------------------
Table2's Data:
-------------------------------------------------
RecordID2 FundID IsChosen ReturnDate Amount2
72083 1588 Yes 09/01/1991 0.0624
97158 1588 Yes 12/01/1991 0.0618
106453 1588 No 09/01/1991 0.0624
106454 1588 No 12/01/1991 0.0618
------------------------------------------------

The amounts of 0.0618 are coming up as different, when
I expect them to come up as the same.

viz:
--------------------------------------------------------------------------
RecordID1 RecordID2 FundID Amount1 Amount2 AmountsDiffer IsChosen
2 106454 1588 0.0618 0.0618 -1 No
--------------------------------------------------------------------------

--
PeteCresswell
Nov 13 '05 #1
4 2599
On Tue, 24 May 2005 21:46:14 -0700, "(PeteCresswell)" <x@y.z.invalid>
wrote:

Sure. Send it over. My spam trap should be obvious.
One thing to consider is to use Currency for monetary values (I'm
assuming Amount* qualify.

-Tom.
I'm equi-joining two tables on a Long and a DateTime field and then
comparing an amount in one with an amount the other via an Immediate If
statement.

Problem is that for some (not all...not even most...) records, I am getting
false differences.

I know the stuff below probably looks like a rat's breakfast, but I'm at the end
of my little string on this. Similar things are happening in a couple other
queries, so I'd have to assume it's something dumb that I'm doing...but I can't
figure out what.

If anybody's got time on their hands and/or some excess curiosity, I could email
you the sample DB - it's only 9k zipped.

This is about as far down as I can pare down the SQL:
--------------------------------
SELECT
Table1.RecordID1,
Table2.RecordID2,
Table1.FundID,
Table1.Amount1,
Table2.Amount2,
IIf([Table2].[Amount2]<>[Table1].[Amount1],True,False) AS AmountsDiffer,
Table2.IsChosen

FROM
Table1 INNER JOIN Table2 ON (Table1.FundID = Table2.FundID) AND
(Table1.ReturnDate = Table2.ReturnDate)

WHERE
(((IIf([Table2].[Amount2]<>[Table1].[Amount1],True,False))=True) AND
((Table2.IsChosen)=False));
--------------------------------

FundID's are Long, ReturnDates are DateTime.
Amounts are Double.

Table1's Data:
--------------------------------------------
FundID ReturnDate Amount1 RecordID1
1588 09/01/1991 0.0624 1
1588 12/01/1991 0.0618 2
--------------------------------------------
Table2's Data:
-------------------------------------------------
RecordID2 FundID IsChosen ReturnDate Amount2
72083 1588 Yes 09/01/1991 0.0624
97158 1588 Yes 12/01/1991 0.0618
106453 1588 No 09/01/1991 0.0624
106454 1588 No 12/01/1991 0.0618
------------------------------------------------

The amounts of 0.0618 are coming up as different, when
I expect them to come up as the same.

viz:
--------------------------------------------------------------------------
RecordID1 RecordID2 FundID Amount1 Amount2 AmountsDiffer IsChosen
2 106454 1588 0.0618 0.0618 -1 No
--------------------------------------------------------------------------


Nov 13 '05 #2
(PeteCresswell) wrote:
WHERE
(((IIf([Table2].[Amount2]<>[Table1].[Amount1],True,False))=True) AND
((Table2.IsChosen)=False));
Can you not use:

where table2.amount2 <> table1.amount1 and table2.ischosen=false

The amounts of 0.0618 are coming up as different, when
I expect them to come up as the same.


Currency or floating point?

--
[OO=00=OO]
Nov 13 '05 #3
Per Trevor Best:
Can you not use:

where table2.amount2 <> table1.amount1 and table2.ischosen=false
I was going with what the query designer came up with - but yes - and certainly
that syntax is more concise. But it still gives the same result. I'm
thinking I have some very basic conceptual problem - like which records show up
under what circumstances....i.e. the query is working correctly but I'm not
specifying correctly.

The amounts of 0.0618 are coming up as different, when
I expect them to come up as the same.


Currency or floating point?


"Decimal" per MS Access.

--
PeteCresswell
Nov 13 '05 #4
Per Tom van Stiphout:
Sure. Send it over.


Sent.
--
PeteCresswell
Nov 13 '05 #5

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

Similar topics

4
by: F | last post by:
Hi I have posted the question few days back about problem in inserting the dates in SQL server and thankful to them who replied. That was solved and this is a nice solution....
1
by: (Pete Cresswell) | last post by:
The scenario: - A system with a couple hundred reports is up and running in production. - Changes are made to the system. - Somebody decrees a full regression test. All reports are...
5
by: Colleyville Alan | last post by:
I have built a SQL statement that is trying to loop through the fields of a table that was built from a spreadsheet and hence is "short and fat". So rather than hard-coding, I have a loop from...
4
by: Shwetabh | last post by:
Hi, My question is, is there any difference between a NULL and a Blank (Unknown, Not Applicable) field in MS SQL or are they the same? Awaiting your comments, Regards
5
by: Stephen Plotnick | last post by:
I'm very new to VB.NET 2003 Here is what I have accomplished: MainSelectForm - Selects an item In a public class I pass a DataViewRow to ItemInformation1 Form ItemInformation2 Form
6
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
10
by: mscurto | last post by:
What is the syntax for an sql command to get the following. I want to pull in a handful of fields from a table but one of the fields needs to be unique. For example, if I have a customer table...
27
by: Thomas Kowalski | last post by:
Hi everyone, To determine equality of two doubles a and b the following is often done: bool isEqual ( double a, double b ) { return ( fabs (a-b) < THRESHOLD ); } But this a approach usually...
1
by: The.Daryl.Lu | last post by:
Hi, two parts to my problem if someone can help address either one or both: 1. I want to SELECT everything in the table if it matches the criteria when the query button is pressed (this is just...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...

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.