473,800 Members | 2,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sql to find a numeric range inside another range?

hi,

i'm building a query to find narrow ranges of zip codes within broader
ranges in a table (for tax purposes). for example:

LOW_ZIP HI_ZIP
23400 23499

need to find
23401 23402
23403 23440
23441 23... you get the picture. :)

so, each row has a low value and a hi value, then i need to run a
subquery to take those values and find narrower ranges. any ideas?
Jul 19 '05 #1
3 10580

"dbarchitec h" <no*******@mac. com> wrote in message
news:9d******** *************** ***@posting.goo gle.com...
| hi,
|
| i'm building a query to find narrow ranges of zip codes within broader
| ranges in a table (for tax purposes). for example:
|
| LOW_ZIP HI_ZIP
| 23400 23499
|
| need to find
| 23401 23402
| 23403 23440
| 23441 23... you get the picture. :)
|
| so, each row has a low value and a hi value, then i need to run a
| subquery to take those values and find narrower ranges. any ideas?

yeah, but you got to show us yours first ;-)

;-{ mcs
Jul 19 '05 #2
"Mark C. Stock" <mcstockX@Xenqu ery .com> wrote in message news:<eP******* *************@c omcast.com>...
"dbarchitec h" <no*******@mac. com> wrote in message
news:9d******** *************** ***@posting.goo gle.com...
| hi,
|
| i'm building a query to find narrow ranges of zip codes within broader
| ranges in a table (for tax purposes). for example:
|
| LOW_ZIP HI_ZIP
| 23400 23499
|
| need to find
| 23401 23402
| 23403 23440
| 23441 23... you get the picture. :)
|
| so, each row has a low value and a hi value, then i need to run a
| subquery to take those values and find narrower ranges. any ideas?

yeah, but you got to show us yours first ;-)

;-{ mcs


yeah, well mine doesn't work!!! :-$

select sales_tax_id,
from_postal_cod e,
to_postal_code
from ar_sales_tax a,
(select from_postal_cod e as fpc,
to_postal_code as tpc
from ar_sales_tax
where rowid = rowid) b
where from_postal_cod e between b.fpc and b.tpc
and to_postal_code between b.fpc and b.tpc
and end_date is null

i need to somehow scan the entire table row by row looking for records
that fit within the ranges... i'm thinking i may need to do this using
a cursor.

-cam
Jul 19 '05 #3

"dbarchitec h" <no*******@mac. com> wrote in message
news:9d******** *************** ***@posting.goo gle.com...
| "Mark C. Stock" <mcstockX@Xenqu ery .com> wrote in message
news:<eP******* *************@c omcast.com>...
| > "dbarchitec h" <no*******@mac. com> wrote in message
| > news:9d******** *************** ***@posting.goo gle.com...
| > | hi,
| > |
| > | i'm building a query to find narrow ranges of zip codes within broader
| > | ranges in a table (for tax purposes). for example:
| > |
| > | LOW_ZIP HI_ZIP
| > | 23400 23499
| > |
| > | need to find
| > | 23401 23402
| > | 23403 23440
| > | 23441 23... you get the picture. :)
| > |
| > | so, each row has a low value and a hi value, then i need to run a
| > | subquery to take those values and find narrower ranges. any ideas?
| >
| > yeah, but you got to show us yours first ;-)
| >
| > ;-{ mcs
|
| yeah, well mine doesn't work!!! :-$
|
| select sales_tax_id,
| from_postal_cod e,
| to_postal_code
| from ar_sales_tax a,
| (select from_postal_cod e as fpc,
| to_postal_code as tpc
| from ar_sales_tax
| where rowid = rowid) b
| where from_postal_cod e between b.fpc and b.tpc
| and to_postal_code between b.fpc and b.tpc
| and end_date is null
|
| i need to somehow scan the entire table row by row looking for records
| that fit within the ranges... i'm thinking i may need to do this using
| a cursor.
|
| -cam

well, know we know that you tried something!

you won't need a cursor, and you won't need to be one either ;-)

i'll take a stab at it, but it would be nice if you could elaborate on
'doesn't work'

regarding your query

select ...
from ar_sales_tax a
,(
select ...
from ar_sales_tax
where rowid = rowid
) b

the rowid=rowid is always true, don't you think?
so there is no added value in that statement
and there is no added value in the in-line view (the in-line subquery you've
aliased as 'b'

so, if that's simplified to
select ...
from ar_sales_tax a
, ar_sales_tax b
where a.from_postal_c ode between b.from_postal_c ode and
b.to_postal_cod e
and a.to_postal_cod e between b.from_postal_o ce and
b.to_postal_cod e
and a.end_date is null

all that's going to do for you is give you rows in the 'A' pass at your
table where rows are found in the 'B' pass with a range of codes that
overlap each of the codes from the 'A' pass -- but it doesn't tell you
anything about the relationship between the two passes, and doesn't limit
the results to any specific pair of codes

assuming you're looking for ranges narrower than your 23400/23499 sample,
how about narrowing one of the passes by that pair of values? or returning
the range from the A pass and the range from the B pass in your select
clause, so that you've got something to work with?

;-{ mcs
Jul 19 '05 #4

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

Similar topics

3
1820
by: Stephen Boulet | last post by:
I have a long list of floats (1613808 elements long). It takes quite a while to load this into a 7 dimensional Numeric array. Is there any obvious way to speed this up? def insertData(self,data): # Start off with an array of the desired size # "self.MEASURED", etc., are integers arrayData = zeros(, Float64)
0
1293
by: beliavsky | last post by:
I have been looking at the speed of Python with the Numeric module by simulating some random numbers and computing some statistics. Here is the code. Line (1) is replaced as shown in the table. from RandomArray import random from Numeric import sum n = 1000000 m = 10 for i in range(m):
24
2328
by: Matt Feinstein | last post by:
Hi all-- I'm new to Python, and was somewhat taken aback to discover that the core language lacks some basic numerical types (e.g., single-precision float, short integers). I realize that there are extensions that add these types-- But what's the rationale for leaving them out? Have I wandered into a zone in the space/time continuum where people never have to read binary data files? Matt Feinstein
1
10311
by: Luigi Ida' via SQLMonster.com | last post by:
Hi, I have a php application connected through odbc to a sqlserver database. When I try to execute select queries on a smalldatetime table field I receive this message: Warning: Numeric value out of range The query is something like: select dateField from table
30
3697
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code seems unnecessarily long. For some while, the following approach has been given here :- function ValidDate(y, m, d) { // m = 0..11 ; y m d integers, y!=0
2
1920
by: MrNobody | last post by:
I just noticed that a numeric up/down will let you manually type in any number even if it is beyond the min/max range you specified. The control will not actually return this value if it is beyond the min/max but it won't give you any indication that the value you typed in is out of range. Any way to get around this so a user typing in a number out of range will get some kind of warning ?
7
1669
by: Sheldon | last post by:
Hi, I have the following loop that I think can be written to run faster in Numeric. I am currently using Numeric. range_va = main.xsize= 600 main.ysize= 600 #msgva is an (600x600) Numeric array with mutiple occurrences of the values in range_va #sat_id is an (600x600) Numeric array with values ranging from -2 to 2
2
2513
by: tron_23 | last post by:
hi, we use Toplink (TopLink - 4.6.0 (Build 417) with a DB2 Database 7.2. i know really old versions, but we could change to e newer one ;-) Sometimes we got some problems with update or insert statements -- numeric value out of range. The SQL statements should be right. We took the statements and we tried to execute it manually. It works... in our programm sometimes it crashed and we get a Database Exception: CLI0111E Numeric value...
3
212
by: dbarchitech | last post by:
hi, i'm building a query to find narrow ranges of zip codes within broader ranges in a table (for tax purposes). for example: LOW_ZIP HI_ZIP 23400 23499 need to find 23401 23402
0
9550
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
10501
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
10273
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
10250
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,...
0
10032
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7574
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
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.