Jump to content

Trouble with SQL Code


gingerwinger

Recommended Posts

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

SELECT *FROM mytableWHERE Trim(Left(postcode, 4)) INĀ  (" &mypostcodes& ")

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

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.

Hello, SELECT *FROM mytableWHERE Trim(Left(postcode, 4)) = (" &mypostcodes& ")
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...