R
Robert Morley
Hi all,
First, sorry for cross-posting, but as I have flexibility on how I do this,
I thought I'd post it to the two most-relevant groups. I can do this either
server-side, using a stored procedure, or I can do it client-side using VBA.
The recordset is only a few thousand records, and we all have at least 3M
down/800k up DSL if not 10/100 LAN connections, so client-side isn't really
a huge deal. Anyway, here's what I'm trying to do:
I'm working in an Access ADP, with SQL Server 2000 as the back-end. I have
a recordset with the following structure (simplified for the sake of keeping
this straight-forward):
AccountID - char (4)
PersonID - int
BeginDate - smalldatetime - date only, always populated (i.e., never NULL)
EndDate - smalldatetime - date only, but NULL if person is currently
assigned to this account (i.e., NULL is treated as higher than any non-NULL
date in a range)
These records are coming to me from a different server, which tracks based
on sub-accounts, and I need to track only by the main account. So for every
record that has the same AccountID/PersonID, I need to coalesce overlapping
date ranges into a single date range using the largest possible range--even
if it mixes the BeginDate from one record with the EndDate from
another--while not coalescing date ranges that are completely separate.
(There's an unrelated unique identifier in the final table, so multiple
AccountID/PersonID with different date ranges are fine in the final
product.)
Note: the source records can either be dealt with as unmodifiable, or I can
dump them into a temp table to allow for modification/deletion of
records...whatever method is easiest.
So to give you an example:
A001 1 2001-Dec-02 2002-Jul-07
A001 1 2003-Jan-01 2005-Jan-31
A001 1 2004-Feb-05 NULL
A001 2 2002-Aug-01 2003-Jul-31
A001 2 2001-Jan-16 2005-Feb-28
should "coalesce" to:
A001 1 2001-Dec-02 2002-Jul-07
A001 1 2003-Jan-01 NULL (combining two records to return largest
range, while not deleting unrelated range)
A001 2 2001-Jan-16 2005-Feb-28 (using only record with largest
range, ignoring the one with embedded range)
Ultimately, I know I can do this in VBA, though I might not use the best
method to get from point A to point B; so if anybody can provide a better
method, great...if you can provide insight into doing it entirely
server-side, even better!
Rob
First, sorry for cross-posting, but as I have flexibility on how I do this,
I thought I'd post it to the two most-relevant groups. I can do this either
server-side, using a stored procedure, or I can do it client-side using VBA.
The recordset is only a few thousand records, and we all have at least 3M
down/800k up DSL if not 10/100 LAN connections, so client-side isn't really
a huge deal. Anyway, here's what I'm trying to do:
I'm working in an Access ADP, with SQL Server 2000 as the back-end. I have
a recordset with the following structure (simplified for the sake of keeping
this straight-forward):
AccountID - char (4)
PersonID - int
BeginDate - smalldatetime - date only, always populated (i.e., never NULL)
EndDate - smalldatetime - date only, but NULL if person is currently
assigned to this account (i.e., NULL is treated as higher than any non-NULL
date in a range)
These records are coming to me from a different server, which tracks based
on sub-accounts, and I need to track only by the main account. So for every
record that has the same AccountID/PersonID, I need to coalesce overlapping
date ranges into a single date range using the largest possible range--even
if it mixes the BeginDate from one record with the EndDate from
another--while not coalescing date ranges that are completely separate.
(There's an unrelated unique identifier in the final table, so multiple
AccountID/PersonID with different date ranges are fine in the final
product.)
Note: the source records can either be dealt with as unmodifiable, or I can
dump them into a temp table to allow for modification/deletion of
records...whatever method is easiest.
So to give you an example:
A001 1 2001-Dec-02 2002-Jul-07
A001 1 2003-Jan-01 2005-Jan-31
A001 1 2004-Feb-05 NULL
A001 2 2002-Aug-01 2003-Jul-31
A001 2 2001-Jan-16 2005-Feb-28
should "coalesce" to:
A001 1 2001-Dec-02 2002-Jul-07
A001 1 2003-Jan-01 NULL (combining two records to return largest
range, while not deleting unrelated range)
A001 2 2001-Jan-16 2005-Feb-28 (using only record with largest
range, ignoring the one with embedded range)
Ultimately, I know I can do this in VBA, though I might not use the best
method to get from point A to point B; so if anybody can provide a better
method, great...if you can provide insight into doing it entirely
server-side, even better!
Rob