473,811 Members | 3,208 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 10586

"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
2332
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
10313
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
3702
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
1921
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
9607
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
10656
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
9214
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7674
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
6897
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();...
0
5564
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...
0
5700
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3878
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3027
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.