Try this :
sql = " SELECT TOP 1 *, ABS(CONVERT(INT,zip) - "
sql = sql & CLng(trim(Request("zipcode"))) + " ) AS 'diff' "
sql = sql & " FROM table "
sql = sql & " WHERE country = '" & cstr(trim(Request("country"))) & "' "
sql = sql & " ORDER BY diff ASC "
Final sql should look like this:
SELECT TOP 1 *, ABS(CONVERT(INT,zip)- 90000 ) AS 'diff' FROM table
WHERE country = 'USA' ORDER BY diff ASC
assuming Request("country") = "USA" and Request("zip") = "90000"
:)heers,
Vanith
: Hi,
:
: I am trying to retrieve records from my Access database.
: I want to retrieve those records whose zip = zipcode (from a form)
: or if that perticular zipcode is not present than find for a nearest zip code to display the record.
:
: select * from table where country = '" + cstr(trim(Request("country"))) + "' and zip='" + cstr(trim(Request("zipcode"))) + "' or zip= "nearest zipcode query"
:
: Can anybody help me out.
:
: r_patel
:
:
:
: