Here is the scenario:
Two tables-1)Prospects table, 2)Events table
Prospects table holds data on the individual and is assigned a unique number 'pkey'.
Events on each individual prospect is recorded in the Events table and is related back to the Prospect table by the foreign key also named 'pkey'. When an event is recorded for a prospect a creation date and a future date is recorded. The future date is the exact same as the creation date if the event is not recorded as a future event. It is different then the creation date if a future date is inputed.
Trying to write a utility in asp for sql server 2000 that will return Prospects that have events with no future dates. I need to query only Distinct Prospects with max future dates that are not beyond today.
Here is what I have so far. It looks good, but under thorough examination there are duplicates.
SELECT DISTINCT a.pkey, a.triggerdate
FROM events a WHERE a.triggerdate =
(SELECT MAX(triggerdate)
FROM events b
WHERE b.pkey = a.pkey
AND b.triggerdate < #02/10/02#);
Thank you,
Ryan
Two tables-1)Prospects table, 2)Events table
Prospects table holds data on the individual and is assigned a unique number 'pkey'.
Events on each individual prospect is recorded in the Events table and is related back to the Prospect table by the foreign key also named 'pkey'. When an event is recorded for a prospect a creation date and a future date is recorded. The future date is the exact same as the creation date if the event is not recorded as a future event. It is different then the creation date if a future date is inputed.
Trying to write a utility in asp for sql server 2000 that will return Prospects that have events with no future dates. I need to query only Distinct Prospects with max future dates that are not beyond today.
Here is what I have so far. It looks good, but under thorough examination there are duplicates.
SELECT DISTINCT a.pkey, a.triggerdate
FROM events a WHERE a.triggerdate =
(SELECT MAX(triggerdate)
FROM events b
WHERE b.pkey = a.pkey
AND b.triggerdate < #02/10/02#);
Thank you,
Ryan