gingerwinger Posted February 27, 2006 Share Posted February 27, 2006 HelloI have a postcode search function I am working on and it searches on distance from a given postcode. This works fine but the problem I am having is that when if there is a postcode in the database like BN12 and someone is searching N12 on the site it recalls the BN12 postcodes also. I'm assuming this is because there is the N12 in the BN12.Is there a way to search exaclty what the user wants so that N12 will only find N12?The code I am using is as follows:SELECT *FROM mytableWHERE Trim(Left(postcode, 4)) IN (" &mypostcodes& ")The mypostcodes bit of the code is a string that recalls all the postcodes within the chosen area.Any help would be greatly appreciated.Many thanks Link to comment Share on other sites More sharing options...
The-Eagle-Eye Posted March 1, 2006 Share Posted March 1, 2006 SELECT *FROM mytableWHERE Trim(Left(postcode, 4)) INĀ (" &mypostcodes& ")<{POST_SNAPBACK}> I m not sure abt it....but i would like to suggest that ... make ur field size of exact 4 for postcode so that it can ignore BN12 with N12. and the value entered in it should be 0N12.Hope this should work out for u.All The Best. Link to comment Share on other sites More sharing options...
syedhameed Posted March 2, 2006 Share Posted March 2, 2006 I m not sure abt it....but i would like to suggest that ... make ur field size of exact 4 for postcode so that it can ignore BN12 with N12. and the value entered in it should be 0N12.Hope this should work out for u.All The Best.<{POST_SNAPBACK}> Hello, SELECT *FROM mytableWHERE Trim(Left(postcode, 4)) = (" &mypostcodes& ") Link to comment Share on other sites More sharing options...
gingerwinger Posted March 2, 2006 Author Share Posted March 2, 2006 Thanks for the reply but the = does not work as there is more than one result being supplied by the mypostcodes.There has to be an answer but its just not coming! Thanks for your support Link to comment Share on other sites More sharing options...
arief_anang Posted March 8, 2006 Share Posted March 8, 2006 Perhaps, you can use this script below:SELECT * FROM mytable WHERE postcode=SUBSTRING(postcode,(4-LENGTH(postcode))+1,LENGTH(postcode))Regards,Anang Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now