473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Nearby zipcodes from a point

Hi,
I have a database of zipcodes,longitude and latitude. I want to
calculate the nearby zipcodes from a specific zipcode. I have the
function that gives the distance between two zipcodes but I need more
robust way to find the nearby zipcodes without looping and calling my
function for 33,000 records of zipcodes.

here is the function I used to get the distance between two zips:
(sql2000 server user defined function)

CREATE FUNCTION dbo.fn_CalcMiles( @LatA FLOAT , @LongA FLOAT , @LatB
FLOAT ,@LongB FLOAT )

RETURNS FLOAT

AS

BEGIN

DECLARE @localRConst FLOAT
DECLARE @localAns FLOAT
DECLARE @localMiles FLOAT

SET @localRConst = 57.3
SET @localAns = 0
SET @localMiles = 0

IF @LatA IS NULL OR @LatA = 0 OR @LongA IS NULL OR @LongA = 0 OR @LatB
IS
NULL OR @LatB = 0 OR @LongB IS NULL OR @LongB = 0
BEGIN
RETURN ( @localMiles )
END

SET @localAns = SIN(@LatA / @localRConst) * SIN(@LatB / @localRConst)
+
COS(@LatA / @localRConst ) * COS( @LatB / @localRConst ) *
COS(ABS(@LongB -
@LongA )/@localRConst)
SET @localMiles = 3959 * ATAN(SQRT(1 - SQUARE(@localAns)) / @localAns)

SET @localMiles = CEILING(@localMiles)

RETURN ( @localMiles )

END
Nov 22 '05 #1
0 1266

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Roger Leigh | last post by:
Hello, I'm writing a fixed-precision floating point class, based on the ideas in the example fixed_pt class in the "Practical C++ Programming" book by Steve Oualline (O' Reilly). This uses a...
2
by: Philip Herlihy | last post by:
I'm getting this bizarre effect in IE6 (not in Firefox, etc). When you hover over the "back" or "next" links, adjacent images are cropped at that vertical level and the page redisplays with that...
4
by: JJA | last post by:
I need to show data for the top 3 zipcodes for EACH of the top 5 counties. I feel totally blocked on how to make this work properly. Here is my code - anything you can suggest will be greatly...
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
1
by: muhammet | last post by:
Hello, I want to add new controls to the blue bar that located at the top of form. I want to add controls nearby the minimize box. Is it possible? Best Regards, Muhammet
39
by: DanielJohnson | last post by:
I wrote a simply program with a 3 D coordinate called point. I am adding two points, taking their distance etc. gcc compiler is not identifying the struct. Here is the code. I get bunch of errors....
1
by: Robert | last post by:
Hello, I need a query where I can give a beginning zipcode and ending zipcode. These zipcodes include some with zip+4. I know to use the between function. Please help. Robert
1
by: hedda | last post by:
I need to link to our database at work and update our customer shipping information (16,000 customers). I have a list of zipcodes (570) I only want to pull customers with or without the zipcodes...
0
by: raylopez99 | last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to modify a Point, which I had made have a property. It's pointless to do this (initially it will compile, but you'll run into...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.