G
Guest
I'm trying to return the row with the maximum [effective date] and
[expiration date] where the member number exists in a joined table and the
[expiration date] is prior to now(). Rows that have the same [effective
date] and [expiration date] are void, so I have to be sure and not return
those (you'll notice it in the where clause). Here's an example of 3 rows
that are the same except for the 2 date fields. When I run my query it
returns all 3 and I want it to only return the one where the most recent
dates are. I've converted the dates into the format below, so feel free to
change the way they look.
Row Values:
MemberID | FirstName | LastName | EffectiveDate |
ExpirationDate
011111 | Jane | Doe | 20020101 |
20020630
011111 | Jane | Doe | 20040401 |
20050531
011111 | Jane | Doe | 20050601 |
20050630
Query:
SELECT DISTINCT l.MemberID, l.FirstNAme, l.LastName, a.EffectiveDate,
a.ExpirationDate
FROM LostMembers AS l INNER JOIN Active AS a ON a.[MemberNo] = l.[MemberID]
WHERE (a.[EffectiveDate] < a.[ExpirationDate]) AND (a.[ExpirationDate] <
Now())
GROUP BY l.MemberID, l.FirstNAme, l.LastName, a.EffectiveDate,
a.ExpirationDate
Thanks,
Matt
[expiration date] where the member number exists in a joined table and the
[expiration date] is prior to now(). Rows that have the same [effective
date] and [expiration date] are void, so I have to be sure and not return
those (you'll notice it in the where clause). Here's an example of 3 rows
that are the same except for the 2 date fields. When I run my query it
returns all 3 and I want it to only return the one where the most recent
dates are. I've converted the dates into the format below, so feel free to
change the way they look.
Row Values:
MemberID | FirstName | LastName | EffectiveDate |
ExpirationDate
011111 | Jane | Doe | 20020101 |
20020630
011111 | Jane | Doe | 20040401 |
20050531
011111 | Jane | Doe | 20050601 |
20050630
Query:
SELECT DISTINCT l.MemberID, l.FirstNAme, l.LastName, a.EffectiveDate,
a.ExpirationDate
FROM LostMembers AS l INNER JOIN Active AS a ON a.[MemberNo] = l.[MemberID]
WHERE (a.[EffectiveDate] < a.[ExpirationDate]) AND (a.[ExpirationDate] <
Now())
GROUP BY l.MemberID, l.FirstNAme, l.LastName, a.EffectiveDate,
a.ExpirationDate
Thanks,
Matt