Forums
This topic is locked
Search by Zip Code
Posted 19 Feb 2002 18:28:51
1
has voted
19 Feb 2002 18:28:51 Brian Milner posted:
I'm trying to add a search function to my site that will allow folks to find the ten nearest locations by zip code. I'm not trying to tap into any actual radius information. I really only wanted to add SQL that would search for the ten zip codes nearest in number to the one entered.Does anyone have a the SQL for this?
Thanks in advance
Replies
Replied 19 Feb 2002 19:22:28
19 Feb 2002 19:22:28 Owen Eastwick replied:
Don't really know about US zip codes, in the UK matching by "text closeness" would return nonsense in terms of geographical location.
That said:
<%
If Request("txtZip" = "" Then
varZIP = "%" 'default value that returns all results
Else
varZIP = Replace(Request("txtZip", "'","''" 'replace those pesky single quotes
End If
%>
RecordsetName.Source = "SELECT * FROM TableName WHERE ZipCodeField LIKE '" & varZIP & "'"
NOTES:
This will find exact mathes:- LIKE '" & varZIP & "'"
This will find a match with any string containing the string varZIP:- LIKE '%" & varZIP & "%'"
This will find a match with any string starting with the string varZIP:- LIKE '%" & varZIP & "'"
This will find a match with any string ending with the string varZIP:- LIKE '" & varZIP & "%'"
Regards
Owen.
Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
That said:
<%
If Request("txtZip" = "" Then
varZIP = "%" 'default value that returns all results
Else
varZIP = Replace(Request("txtZip", "'","''" 'replace those pesky single quotes
End If
%>
RecordsetName.Source = "SELECT * FROM TableName WHERE ZipCodeField LIKE '" & varZIP & "'"
NOTES:
This will find exact mathes:- LIKE '" & varZIP & "'"
This will find a match with any string containing the string varZIP:- LIKE '%" & varZIP & "%'"
This will find a match with any string starting with the string varZIP:- LIKE '%" & varZIP & "'"
This will find a match with any string ending with the string varZIP:- LIKE '" & varZIP & "%'"
Regards
Owen.
Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo