finding the nearest to

A

admlcl

I'm rewritting a app (in VB6) and adding an Access 2000 database to
replace textfiles,there will be a number of tables,one of the tables
will have a list of text (field1)and numbers(field2),I need to be able
to find the number closest to the result of a calcutlation,ie, if
field2 has numbers 1.1,1.132,1.183,1.2025 etc,and the result of the
calc is 1.169 then the closest number is 1.183,what sort of sql command
would I need? I'm new at mdb stuff so any pointers would be greatly
appreciated
SteveC
 
D

Dirk Goldgar

I'm rewritting a app (in VB6) and adding an Access 2000 database to
replace textfiles,there will be a number of tables,one of the tables
will have a list of text (field1)and numbers(field2),I need to be able
to find the number closest to the result of a calcutlation,ie, if
field2 has numbers 1.1,1.132,1.183,1.2025 etc,and the result of the
calc is 1.169 then the closest number is 1.183,what sort of sql
command would I need? I'm new at mdb stuff so any pointers would be
greatly appreciated
SteveC

Here's an example of that sort of thing:

SELECT tblNumbers.* FROM tblNumbers
WHERE (((Abs([Field2]-[Enter number])) =
(SELECT Min(Abs([Field2]-[Enter number])) FROM tblNumbers)));

In this case, [Enter number] is a parameter to prompt for the number you
want to look up.
 
Top