Question : sql distance calc

I have to develop a solution to show all locations within a 50 mile radius of the entered zip code.
I have bits and pieces working, but cannot show them sorted by distance.  I either need to go to a stored procedure or find a way to get javascript return into a variable within an asp loop.
I have to have it working by Monday.
It doesn't involve that much code, I don't know javascript that well and my attempts to incoroprate the distance function into the stored procedure are not working.
I have two tables - zipcodes with a list of all zip codes with longitude and latitude and the other with the list of locations, also with zip, to which I've added longitude and latitude to the test sample to make it easier, but there is a huge database that only has zip code which I'd rather work with if I can.
Thanks in advance for tackling this - I've been working on it a week solid.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:

 
This displays it real time and it is where I need it returned into a variable because it's in a loop:
This is the sql statements. The first gets the start point, the second gets all the locations within the entered zip's longitude and latitude: SQL = "Select zip,longitude,latitude from ZipCodes where zip = '"&szip&"'" SQL_Rs.open SQL,SQL_Cn,3 If NOT(SQL_Rs.EOF) then startlon = SQL_Rs.fields("longitude") startlat = SQL_Rs.fields("latitude") End If SQL_Rs.close SQL = "SELECT DISTINCT A.dblvl, A.dblvlnm,A.dbsec, A.dbsec2, A.dbsec3, A.dbsec4, A.dbsec5, A.dbsec6, A.dbsec7, A.longitude, A.latitude,B.longitude, B.latitude FROM db11 AS A INNER JOIN (SELECT Zip, latitude, longitude FROM ZipCodes WHERE ZIP='"&szip&"') AS B ON CAST(A.latitude AS decimal) BETWEEN CAST(B.latitude AS decimal) - "&varradius&" AND CAST(B.latitude AS decimal) + "&varradius&" AND CAST(A.longitude AS decimal) BETWEEN CAST(B.longitude AS decimal) - "&varradius&" AND CAST(B.longitude AS decimal) + "&varradius&" order by b.latitude,b.longitude" SQL_Rs.open SQL,SQL_Cn,3 IF NOT(SQL_Rs.EOF) THEN arrZips = SQL_Rs.getrows toprec=ubound(arrZips,2) END IF SQL_Rs.close

Answer : sql distance calc

Whoops - didn't know the rules.  I should read more.
Still would like ome help on this - don't have time or resources to add sql2008 right now.
Random Solutions  
 
programming4us programming4us