Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want to compare 2 fields, must I convert?

Status
Not open for further replies.

srogers

Technical User
Aug 15, 2000
201
US
I have 2 numbers from two different tables I want to compare.

The datatypes look like this:

table datatype length precision
table1 float 8 53
table2 numeric 9 19


In table 1 the number 53 appears.
In table 2 it shows up as 5300

Ultimately I only want to retrieve records where
table1.field1 <> table2.field2

I tried doing it &quot;as-is&quot; hoping for an implicit conversion but the results show that it thinks 53 and 5300 are not equal.

I tried this:
Code:
select (str(table2.costvalue, 10, 2))
from table2

and here's what I get:

5300.00


I tried this:
Code:
select (convert(float(9), table2.costvalue, 0))
from table2

and got this:
5300.0

So maybe I am doing the conversions wrong. I am guessing this would be best done in the Where statment even though the code I show is a select.
Any ideas?
Thank you.
 

How about trying something like this?

Where cast(table1.field1 As numeric(10,2))
<> cast(table2.field2 As numeric(10,2)/100.)
Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Thank you for your reply.
I tried it and it works. What I used before I received this was: Where (OldCost.cost <> (CurrentCost.costvalue / 100))

Have a great day.
Sharon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top