sql query returning closest value
Posted on 2013-11-19
I'm not sure if is the correct forum and the question may be a little long as I'm trying to give you as much info that I can.
I'm working on a real estate system.
I have a page that asks the user for a street number
and a street name. The end result displays all the address on a avenue between 2 streets.
This in Manhattan so everything above 14th street is a grid.
The file that I'm querying looks something like this:
Bld # Street North South
590 Lexington 42 41
591 Lexington 42 41
595 Lexington 41 40
596 Lexington 41 40
What I'm trying to do is, if the user keys in "592 Lex" find the closest number to (in this case "591") and display the addresses on that block ( 42nd to 41st).
Is there a way to use a sql query and tell it that I want the closest value to the address number?
The code does work if I get a hit on a legit address. The problem with real estate is that you never know how they assign building numbers.