Link to home
Start Free TrialLog in
Avatar of Pachecda
Pachecda

asked on

Access 2003 query records that are null and latest dates in Date Field.

MS Access 2003

I'm trying to combined two tables based on one field called user ID. Table 1 shows all users with current activity that shows the right data. Table two contains multiple duplicate user ids with an empty date field (meaning active) or with and End Date field (termination date). However, Termination date could have more than one and would like to query the latest date.
So in Summary, my report is currently pulling the data with a (is null criteria) in the date field. I just dont know how to pulled the latest date of the ones that have been terminated.
The joins I'm using is all records from table 1 and inlcudes all matching records from table 2. Criteria on Table 2 is Date Fiels Is null.

Any suggestions How can I do this so I get all the null dates and the latest date of termination in my report.
Avatar of Atropa
Atropa

Select * From [Table 1] Left Join [Table 2] On [Table 1].ID = [Table 2].UserID Where [Table 2].[DateField] Is Null or [TerminationDate] = DMax("[TerminationDate]", "[Table 1]")

That should give you what you want if I read that correctly...a
Avatar of Pachecda

ASKER

Hi Atropa,

Below is my SQL, I need to add the Max Dt_End date to pull the most recent Date. I tried your solution, but I'm getting confused with the "([])". I need the Max function to pull the most recent date in the DT_End. Currently I'm pulling only null items.
SELECT [Table1].*, Table2.DT_END
FROM [Table1] LEFT JOIN table2 ON ([table1].USERID = table2.USERID) AND ([table1].EXPORT_GROUP_ID = table2.EXPORT_GROUP_ID)
WHERE (((table2.DT_END) Is Null ));
SELECT [Table1].*, Table2.DT_END
FROM [Table1] LEFT JOIN table2 ON ([table1].USERID = table2.USERID) AND ([table1].EXPORT_GROUP_ID = table2.EXPORT_GROUP_ID)
WHERE (((table2.DT_END) Is Null ) Or (table2.Dt_END = DMax("DT_END", "table2")));
HI Atropa,

Thanks for the quick response, I was able to run the query. However, it only pull one with todays date and all null items. My DT end has to pull the most recent date per user id plus null items. For instance;
UserID          DT End
A                  03/01/2005
A                  12/31/2006
B                  02/28/2004
B                  Null
I want to pull user id A with DT_End 12/31/2006 and user ID B with DT End Null Item. Currently is pulling todays date based on your sintax above.
SELECT [Table1].*, Max(Table2.DT_END) As DT_END
FROM [Table1] LEFT JOIN table2 ON ([table1].USERID = table2.USERID) AND ([table1].EXPORT_GROUP_ID = table2.EXPORT_GROUP_ID)
WHERE (((table2.DT_END) Is Null ))
GROUP BY [Table1].UserID, [Table1].[Any other fields];
Hi Atropa,

With the sintax above now I'm getting all null values in the DT_End and nothing with latest dates
HI Experts,

I was able to solve my problem above by using the Totals sigma sign and using  max value in DT_END
Oh yeah, that'll work too.  Leave it to the experts to over-complicate things!
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial