Question : Basic steps for a Zip code search ASP.NET VB, MS SQL 2008

I have 3 tables.  
PostalCodes  has  a list of all the cities and their zip codes + lat & long. in the US  (City, State, Zip, Lat, Long)

Cities
USERID                  CITYNAME            STATE

Members
USERID                  NAME

Columns CityName, State in Table Cities matches City, State in PostalCodes
Column UserID in table Cities matches UserID in Members


So what I want to do is have someone enter a zip code in text box.  Then I need to find NAME, CITYNAME, STATE within a radius of X miles (or KM), if such a record exists.

Can someone point me in the right direction to do this?  I'm sure I have all the data I need to do this.
what are the basic steps of doing this

Answer : Basic steps for a Zip code search ASP.NET VB, MS SQL 2008

How about something like:
SELECT NAME,CITYNAME,STATE FROM Members,Cities,PostalCodes
   WHERE Members.USERID=Cities.USERID
     AND PostalCodes.CITY=Cities.CITYNAME AND PostalCodes.State=Cities.STATE
     AND (PostalCodes.Lat*69.4-@VMILES)*(PostalCodes.Lat*69.4-@VMILES)-
         (PostalCodes.Long*44-@HMILES)*(PostalCodes.Long*44-@HMILES) < X2

where @VMILES is the entered latitude multiplied by 69.4 and @HMILES is the entered longitude multiplied by 44.  (I'm not sure if that's the right parameter format for ASP;
fix it if necessary.  This is untested.)
69.4 is miles in a degree of latitude (earth's circumference about 25000 miles/360).
44 is my guess for longitude in the U.S.  I think it should be 1/360 of the circumference times the sine of the latitude, but I'm not positive.  If it ends up working, you can refine it by looking it up or figuring it out.  It will still be inaccurate because it will be based on average latitude.  You'd have to take latitude into account as well to figure it exactly; it would be more complicated and I don't know how to do it.
X2 is the radius you want to search within, squared.  So the where condition is the Pythagorean theorem.
Random Solutions  
 
programming4us programming4us