473,775 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Nearby zipcodes from a point

Hi,
I have a database of zipcodes,longit ude 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_CalcMile s( @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(@localAn s)) / @localAns)

SET @localMiles = CEILING(@localM iles)

RETURN ( @localMiles )

END
Nov 22 '05 #1
0 1280

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

Similar topics

4
7852
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 long int to store the value, and the precision (number of decimal points) is variable (it's a templated class): template <size_t _decimal_places = 4> class FixedFloat {
2
1982
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 point at the bottom. http://www.walthamsoft.com/assist/2.htm (This page, at least, validates. Don't look much further or you'll see things that will make you shudder at their ineptitude - I'm still learning CSS!) I don't see this effect in...
4
1357
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 appreciated: SET ROWCOUNT 5 DECLARE @tblTopMarkets TABLE (StateCD CHAR(2), CountyCD CHAR(3)) INSERT INTO @tblTopMarkets select S.StateCD, S.CountyCD
65
12610
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 method was a piece of C code which turned out to be incorrect and incomplete but by modifieing it would still be usuable. The first method was this piece of text:
1
1360
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
3110
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. The main ones are : useless storage class specifier in empty declaration, 'point' undeclared (first use in this function), 'p1' undeclared (first use in this function) etc. Any help will be appreciated. Thanks #include <stdio.h> #include...
1
1217
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
1026
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 on the list. I've tried using IN and building a (temp) table but nothing seems to be working. I would like to find out how to do this using query, or a SIMPLE way!! Being linked to the live database, always makes me nervous! THANK YOU
0
2195
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 problems later). Apparently Point is a struct, a value type, and it does not behave like a classic structure (in my mind's eye, and see below). Traditionally I think of a classic structure as simply an object where every member is public. But with...
0
9621
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10267
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7463
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5358
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.