COMPARE FIELDS QUERY

  • Thread starter Thread starter Simon Gare
  • Start date Start date
S

Simon Gare

Hi

I need a query that searches 2 fields in 2 tables. Below is an example.

There are 2 numeric fields in each of the 2 tables containing numbers such
as 51.565842 in 1 field and -0.331336 in another . I need the query to
search the other table and to compare the first 3 digits ie 51.5 and -0.33
and return a result, if that result returns more than 1 record then the
query searches the next digit ie 51.56 and -0.331 and so on until only 1
record is returned.

I know this may sound complicated, but i really need help on this one.

Thanks in advance.

Simon Gare
 
This question should have been asked in the m.p.sqlserver.programming
newsgroup.

The easiest way to do this would be to create a temporary or a variable
table and then, by using a cursor on the first table, populate the temporary
table with the relevant records of the second table. The comparaison between
digits can be achieved by converting the numeric fields to strings (you can
also use rounding but this is a little more complicated).

If you store the primary key of the first table along the records in the
temporary table, then joining these two tables will be a piece of cake when
the scanning of the first table with the cursor will be finished.
 
Back
Top