SQL complexity problem.

1. Junior Member
Join Date
Dec 1969
Posts
26

## SQL complexity problem.

If this question has already been answered, I apologize. I couldn&#039;t find it though.<BR><BR>What I have is a form that allows the user to specify quite a bit of search criteria.. including a search radius based upon thier Zip Code. That is my problem. Depending on the distance of the radius, the amount of Zip Codes that need to be included in the final SQL statement can be extremely large (hundreds). In other words, I need to say:<BR><BR>SELECT * FROM Users WHERE Zipcode=12345 OR Zipcode=67890.. etc.. etc.. <BR><BR>I can&#039;t use stored procedures.. so I have to find another way. The other criteria that is being used in the SELECT .. WHERE statement is no problem. Although there is about 15 different items, it&#039;s short. <BR><BR>I hope I made some sense.. Thanks,<BR><BR>--Tim

2. Senior Member
Join Date
Dec 1969
Posts
940

## RE: SQL complexity problem.

Tim - Would your zip codes happen to be within certain range for a given search radius? I was thinking that maybe the BETWEEN statement could be used here. Something like this:<BR><BR>SELECT * <BR>FROM Users <BR>WHERE Zipcode BETWEEN 12345 AND 12450<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
7,686

## RE: SQL complexity problem.

http://www.aspmessageboard.com/forum/showMessage.asp?F=27&M=351493&P=1<BR><BR>or do a search for &#039;radius&#039;

4. Junior Member
Join Date
Dec 1969
Posts
26

## RE: SQL complexity problem.

Unfortunately Zip Codes don&#039;t seem to be contiguous based on distance. In other words.. 1001 may be in a 25 mile radius while 1002 may not be and 1003 could be. :) <BR><BR>--Tim

5. Junior Member
Join Date
Dec 1969
Posts
26

## RE: SQL complexity problem.

Hmm, I think I understand what is being implied. The way I am approaching it now is to:<BR><BR>1. Get a list of all Zip Codes that fall with a distance (from a separate database which contains the latitudes and longitudes)<BR><BR>2. Then I attempt to search the user database and only return Zip Codes that match the ones found in my previous search.<BR><BR>I will re-read the article you attached and see what I can do with that. I know it can be done so it&#039;s just a matter of me not being so ignorant. :)<BR><BR>--Tim

6. Junior Member
Join Date
Dec 1969
Posts
26

## RE: SQL complexity problem (a follow up)

Dutch,<BR><BR>Using the information found in the article you cross referenced, I found a solution. My results are about 90% accurate. I just need to weed out some of the results that don&#039;t actually fall within the desired radius. As the article suggested, the larger the radius the more undesired results will be returned. No problem though. Thanks.<BR><BR>--Tim

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•