Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / January 2008

Tip: Looking for answers? Try searching our database.

Last Date

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dsc2bjn - 21 Jan 2008 20:15 GMT
I need to be able to find the latest date of multiple record which belong to
a parent record, but only if all the child records have an actual completion
date.

I have all my children records in a table linked to the parent record using
a [Report Number].  

Any suggestions would be appreciated.
George Nicholson - 21 Jan 2008 21:56 GMT
Create a Select query that, for each parent recordID, gives you a count of
all children, a count of completion dates and the Max date of related
children.

Create a 2nd query that references the first query, selecting parent
recordID, maxDate WHERE ChildCount = CompletedCount.

Signature

HTH,
George

>I need to be able to find the latest date of multiple record which belong
>to
[quoted text clipped - 7 lines]
>
> Any suggestions would be appreciated.
Chris Anderson [MVP-VB] - 21 Jan 2008 22:55 GMT
> Create a Select query that, for each parent recordID, gives you a count of
> all children, a count of completion dates and the Max date of related
> children.
>
> Create a 2nd query that references the first query, selecting parent
> recordID, maxDate WHERE ChildCount = CompletedCount.

Expanding on that, something like this:

SELECT *
FROM table1 T1
INNER JOIN (SELECT T.ID, MAX(T.EffDate) AS MaxDate FROM Table1 T GROUP
BY T.ID) T ON T1.ID = T.ID AND T1.EffDate = T.MaxDate

-ca
Larry Daugherty - 21 Jan 2008 22:00 GMT
Use the "TOP n" predicate to return only the number you want of dates
which are sorted DESCending and that are not Null.

HTH
Signature

-Larry-
--

> I need to be able to find the latest date of multiple record which belong to
> a parent record, but only if all the child records have an actual completion
[quoted text clipped - 4 lines]
>
> Any suggestions would be appreciated.
NetworkTrade - 23 Jan 2008 00:19 GMT
Presuming you have the Parent table query already returning the correct
parent records - and what you next need to do is narrow that down to the most
recent date only;    Try using the 'Top X' feature in query design....the
drop down default is Top 10 or Top 5...but you can put your cursor in there
and change to Top 1....

This will give you the greatest, or most recent date record...

Signature

NTC

> I need to be able to find the latest date of multiple record which belong to
> a parent record, but only if all the child records have an actual completion
[quoted text clipped - 4 lines]
>
> Any suggestions would be appreciated.
Ken Sheridan - 23 Jan 2008 01:49 GMT
How you do it depends on whether you want to return columns from the
referencing (child) table other than the completion date.  If you only want
columns from the referenced (parent) table and the date from the referencing
table then a simple aggregating query is all that's needed, e.g.

SELECT [SomeField], [SomeOtherField],
MAX ([Completion Date] AS [LatestDate]
FROM [FirstTable] INNER JOIN [SecondTable]
ON [FirstTable].[Report Number] = [SecondTable].[Report Number]
WHERE [Completion Date] IS NOT NULL
GROUP BY [SomeField], [SomeOtherField];

If you want columns other than CompletionDate from the referenced table
(lets assume a column [PhaseNumber] from the second table) then you need to
use a subquery to identify the latest date:

SELECT [SomeField], [SomeOtherField],
[PhaseNumber], [Completion Date] AS [LatestDate]
FROM [FirstTable] INNER JOIN [SecondTable] AS ST1
ON [FirstTable].[Report Number] =ST1.[Report Number]
WHERE ST1.[Completion Date] =
   (SELECT MAX([Completion Date])
     FROM [SecondTable] AS ST2
     WHERE ST2.[Report Number] = ST1.[Report Number]);

Note how in the second query the different instances of the second table are
distinguished by aliases ST1 and ST2, allowing the subquery to be correlated
with the outer query.  Its not necessary to test for IS NOT NULL in the
subquery, as if all the completion date columns for a particular report
number are NULL the subquery will return NULL.  ST2.[Completion Date] =  NULL
will evaluate to NULL, never to TRUE as comparing anything with NULL, even
NULL, always results in NULL.  This is because NULL is an absence of a value,
an unknown, so comparing anything with an unknown must result in another
unknown.

Ken Sheridan
Stafford, England

> I need to be able to find the latest date of multiple record which belong to
> a parent record, but only if all the child records have an actual completion
[quoted text clipped - 4 lines]
>
> Any suggestions would be appreciated.
Ken Sheridan - 23 Jan 2008 01:49 GMT
How you do it depends on whether you want to return columns from the
referencing (child) table other than the completion date.  If you only want
columns from the refernced (parent) table and the date from the referencing
table then a simple aggregating query is all that's needed, e.g.

SELECT [SomeField], [SomeOtherField],
MAX ([Completion Date] AS [LatestDate]
FROM [FirstTable] INNER JOIN [SecondTable]
ON [FirstTable].[Report Number] = [SecondTable].[Report Number]
WHERE [Completion Date] IS NOT NULL
GROUP BY [SomeField], [SomeOtherField];

If you want columns other than CompletionDate from the referenced table
(lets assume a column [PhaseNumber] from the second table) then you need to
use a subquery to identify the latest date:

SELECT [SomeField], [SomeOtherField]
[PhaseNumber], [Completion Date] AS [LatestDate]
FROM [FirstTable] INNER JOIN [SecondTable] AS ST1
ON [FirstTable].[Report Number] =ST1.[Report Number]
WHERE ST1.[Completion Date] =
   (SELECT MAX([Completion Date])
     FROM [SecondTable] AS ST2
     WHERE ST2.[Report Number] = ST1.[Report Number]);

Note how in the second query the different instances of the second table are
distinguished by aliases ST1 and ST2, allowing the subquery to be correlated
with the outer query.  Its not necessary to test for IS NOT NULL in the
subquery, as if all the completion date columns for a particular report
number are NULL the subquery will return NULL.  ST2.[Completion Date] =  NULL
will evaluate to NULL, never to TRUE as comparing anything with NULL, even
NULL, always results in NULL.  This is because NULL is an absence of a value,
an unknown, so comparing anything with an unknown must result in another
unknown.

Ken Sheridan
Stafford, England

> I need to be able to find the latest date of multiple record which belong to
> a parent record, but only if all the child records have an actual completion
[quoted text clipped - 4 lines]
>
> Any suggestions would be appreciated.

> I need to be able to find the latest date of multiple record which belong to
> a parent record, but only if all the child records have an actual completion
[quoted text clipped - 4 lines]
>
> Any suggestions would be appreciated.
Ken Sheridan - 23 Jan 2008 01:50 GMT
How you do it depends on whether you want to return columns from the
referencing (child) table other than the completion date.  If you only want
columns from the refernced (parent) table and the date from the referencing
table then a simple aggregating query is all that's needed, e.g.

SELECT [SomeField], [SomeOtherField],
MAX ([Completion Date] AS [LatestDate]
FROM [FirstTable] INNER JOIN [SecondTable]
ON [FirstTable].[Report Number] = [SecondTable].[Report Number]
WHERE [Completion Date] IS NOT NULL
GROUP BY [SomeField], [SomeOtherField];

If you want columns other than CompletionDate from the referenced table
(lets assume a column [PhaseNumber] from the second table) then you need to
use a subquery to identify the latest date:

SELECT [SomeField], [SomeOtherField]
[PhaseNumber], [Completion Date] AS [LatestDate]
FROM [FirstTable] INNER JOIN [SecondTable] AS ST1
ON [FirstTable].[Report Number] =ST1.[Report Number]
WHERE ST1.[Completion Date] =
   (SELECT MAX([Completion Date])
     FROM [SecondTable] AS ST2
     WHERE ST2.[Report Number] = ST1.[Report Number]);

Note how in the second query the different instances of the second table are
distinguished by aliases ST1 and ST2, allowing the subquery to be correlated
with the outer query.  Its not necessary to test for IS NOT NULL in the
subquery, as if all the completion date columns for a particular report
number are NULL the subquery will return NULL.  ST2.[Completion Date] =  NULL
will evaluate to NULL, never to TRUE as comparing anything with NULL, even
NULL, always results in NULL.  This is because NULL is an absence of a value,
an unknown, so comparing anything with an unknown must result in another
unknown.

Ken Sheridan
Stafford, England

> I need to be able to find the latest date of multiple record which belong to
> a parent record, but only if all the child records have an actual completion
[quoted text clipped - 4 lines]
>
> Any suggestions would be appreciated.

> I need to be able to find the latest date of multiple record which belong to
> a parent record, but only if all the child records have an actual completion
[quoted text clipped - 4 lines]
>
> Any suggestions would be appreciated.
Ken Sheridan - 23 Jan 2008 01:52 GMT
How you do it depends on whether you want to return columns from the
referencing (child) table other than the completion date.  If you only want
columns from the refernced (parent) table and the date from the referencing
table then a simple aggregating query is all that's needed, e.g.

SELECT [SomeField], [SomeOtherField],
MAX ([Completion Date] AS [LatestDate]
FROM [FirstTable] INNER JOIN [SecondTable]
ON [FirstTable].[Report Number] = [SecondTable].[Report Number]
WHERE [Completion Date] IS NOT NULL
GROUP BY [SomeField], [SomeOtherField];

If you want columns other than CompletionDate from the referenced table
(lets assume a column [PhaseNumber] from the second table) then you need to
use a subquery to identify the latest date:

SELECT [SomeField], [SomeOtherField]
[PhaseNumber], [Completion Date] AS [LatestDate]
FROM [FirstTable] INNER JOIN [SecondTable] AS ST1
ON [FirstTable].[Report Number] =ST1.[Report Number]
WHERE ST1.[Completion Date] =
   (SELECT MAX([Completion Date])
     FROM [SecondTable] AS ST2
     WHERE ST2.[Report Number] = ST1.[Report Number]);

Note how in the second query the different instances of the second table are
distinguished by aliases ST1 and ST2, allowing the subquery to be correlated
with the outer query.  Its not necessary to test for IS NOT NULL in the
subquery, as if all the completion date columns for a particular report
number are NULL the subquery will return NULL.  ST2.[Completion Date] =  NULL
will evaluate to NULL, never to TRUE as comparing anything with NULL, even
NULL, always results in NULL.  This is because NULL is an absence of a value,
an unknown, so comparing anything with an unknown must result in another
unknown.

Ken Sheridan
Stafford, England

> I need to be able to find the latest date of multiple record which belong to
> a parent record, but only if all the child records have an actual completion
[quoted text clipped - 4 lines]
>
> Any suggestions would be appreciated.
Dale Fye - 23 Jan 2008 01:52 GMT
What do you want to do if all of the child recods don't have a completion date?

To get the latest date entered for a particular [Report Number], where the
completion date has a value then, try something like:

SELECT [Report Number], Max([Completion Date]) as LatestDate
FROM yourTable
WHERE [Report Number] = 1
AND [Completion Date] is not NULL

HTH
Dale

Signature

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.

> I need to be able to find the latest date of multiple record which belong to
> a parent record, but only if all the child records have an actual completion
[quoted text clipped - 4 lines]
>
> Any suggestions would be appreciated.
Dale Fye - 23 Jan 2008 01:59 GMT
What do you want to do if all of the records for a particular parent do not
have a completion date?

You might try something like the following.  This would give you the latest
non-null Completion date for each [Report Number].

SELECT [Report Number], Max([Completion Date]) as LatestDate
FROM yourTable
WHERE [Completion Date] IS NOT NULL
GROUP BY [Report Number]

If you only want this value for a single [Report Number] then add a criteria
to the WHERE clause for that [Report Number].

HTH
Dale

Signature

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.

> I need to be able to find the latest date of multiple record which belong to
> a parent record, but only if all the child records have an actual completion
[quoted text clipped - 4 lines]
>
> Any suggestions would be appreciated.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.