Re: MS Access iterators?
- From: "Anthony England" <aengland@xxxxxxxxxx>
- Date: Tue, 7 Feb 2006 21:02:56 +0000 (UTC)
"MGFoster" <me@xxxxxxxxxxx> wrote in message
news:Zq7Gf.11089$1n4.4262@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
What do you mean by "next record"? There is no order to the rows in a
table. The only order is imposed by the ORDER BY clause in a query, or
implied in the criteria (the WHERE clause) of the query.
If by "next" you mean the next ID number in numerical order; and, your
example would mean that ID is 900 would be the "next" row with a Level
of -1, then try this:
SELECT ID, Description, Level
FROM Table
WHERE ID >= 600
AND ID < (SELECT MIN(ID) FROM Table
WHERE ID > 600 AND Level = -1)
The "next" row is implied in the subquery.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBQ+kDNoechKqOuFEgEQKuygCdFd7x1lXTZEUNDDB9Gp31SGVUrBkAn1Hp
q3IbP1S7KFWPMFfjbWhFxl00
=3LC+
-----END PGP SIGNATURE-----
jibber wrote:
I have an application that stores data using iterators (as below)
ID Description Level
600 Demolition -1
670 Demo Exterior Flat Work 0
675 Remove Foundation Walls 0
680 Remove Concrete Stoops/Steps 0
900 Concrete Curb Cutting & Coring -1
910 Core Through Existining 0
I want to retreive the data from 0600 upto the next record with a
"Level = -1."
SELECT ID, Description, Level
FROM Table
WHERE ID > 600 but < Next Record with "Level= -1"
I agree with all you have said, and you just beat me to a solution. The
only comment I would have is that, in general, there may not be that 'next
record' so you could use a Nz function with a number 'bigger than the normal
range for the table' so that if the record isn't found, it selects all
records from 600 upwards:
SELECT tblTable.*
FROM tblTable
WHERE id>600 and id<Nz((select min(id) from mytable where id>600 and
level=-1),999999)
ORDER BY id;
.
- References:
- MS Access iterators?
- From: jibber
- Re: MS Access iterators?
- From: MGFoster
- MS Access iterators?
- Prev by Date: Re: What's "required" to get work in Access these days?
- Next by Date: Re: Compact and repair back end?
- Previous by thread: Re: MS Access iterators?
- Next by thread: Append query from Oracle Back-End
- Index(es):
Relevant Pages
|
Loading