Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-access > #1165

Re: Determining Latest "First" Occurrance In Discontiguous Stream?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From John Spencer <JSPENCER@Hilltop.umbc>
Newsgroups comp.databases.ms-access
Subject Re: Determining Latest "First" Occurrance In Discontiguous Stream?
Date Mon, 02 May 2011 12:13:39 -0400
Organization The Hilltop Institute
Lines 83
Message-ID <ipml7k$7im$1@dont-email.me> (permalink)
References <lgetr65q28rsdftm53i432v5movo5s2t8p@4ax.com>
Reply-To JSPENCER@Hilltop.INVALID
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Mon, 2 May 2011 16:13:40 +0000 (UTC)
Injection-Info mx01.eternal-september.org; posting-host="iasdvEo3UqBsocyxFZ2gbg"; logging-data="7766"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19l2UBGTsI1mlLE0F7FJozAQ7XsiS4WJyU="
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10
In-Reply-To <lgetr65q28rsdftm53i432v5movo5s2t8p@4ax.com>
Cancel-Lock sha1:XZssLFKQ3srQ2i8DzGBjz9SuXVM=
Xref x330-a1.tempe.blueboxinc.net comp.databases.ms-access:1165

Show key headers only | View raw


Step One: Identify all the Purchase Dates for each tranche
SELECT A.TrancheID, A.StatusDate
FROM tblTrancheHeldStatus as A LEFT JOIN tblTrancheHeldStatus as B
ON A.TrancheID = B.TrancheID
AND A.StatusDate = B.StatusDate - 1
WHERE B.TrancheID is Null

Step 2: Now get the maximum purchase date for each TrancheID
SELECT TrancheID, Max(StatusDate) as LatestPurchaseDate
FROM qPurchaseDate
GROUP BY TrancheID

If that works you can probably combine that into one query
SELECT TrancheID, Max(StatusDate) as LatestPurchaseDate
FROM (
    SELECT A.TrancheID, A.StatusDate, A.Status
    FROM tblTrancheHeldStatus as A LEFT JOIN tblTrancheHeldStatus as B
    ON A.TrancheID = B.TrancheID
    AND A.StatusDate = B.StatusDate - 1
    WHERE B.TrancheID is Null) as Results
GROUP BY TranceID


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

On 5/2/2011 10:22 AM, (PeteCresswell) wrote:
> Got a table "tblTrancheHeldStatus":
>
>    TrancheID
>    StatusDate
>    StatusTimeStamp
>
> Contains one record for each day a Tranche was held.
>
> If we own a Tranche on a date, a record gets added to the table.
>
> If a Tranche was not owned on a date, there is no record in the
> table.
>
> On the date a Tranche is sole completely, there is no record in
> the table.
>
> Tranches get purchased, sold completely at some later date, and
> then re-purchased at a still later date multiple times.
>
> Based on the table, I need to determine the most recent date upon
> which a Tranche was re-purchased.
>
> e.g.
> 01/01 = initial buy (record added to table)
> 01/02-01/20 = held on all those days
>                (record added to table for each day)
> 01/21 = sold completely (no record in table)
>
> 02/02 = re-purchased (record added to table)
> 02/03-03/01 = held on all those days
>                (record added to table for each day)
> 03/02 = sold completely (no record in table)
>
> 04/29 = re-purchased (record added to table)
> 04/30-present = held
>                  (record added to table for each day)
>
>
> Somehow, I need to come up with 4/29 without bringing the user's
> PC to it's knees.
>
> I could add a "PurchasedNotHeld" column to the table and set it
> to "True" on the dates a Tranche is purchased when there is no
> balance for it - and then just query for the most recent record
> where it is set.
>
> But that would add more code to the app and also complicate both
> initial population and re-creation of the table.
>
>
> Can anybody suggest something based on the table as it currently
> is?

Back to comp.databases.ms-access | Previous | NextPrevious in thread | Find similar


Thread

Determining Latest "First" Occurrance In Discontiguous Stream? "(PeteCresswell)" <x@y.Invalid> - 2011-05-02 10:22 -0400
  Re: Determining Latest "First" Occurrance In Discontiguous Stream? John Spencer <JSPENCER@Hilltop.umbc> - 2011-05-02 12:13 -0400

csiph-web