Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2007-03-27
10
953 Views
Last Modified: 2008-03-14
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.
0
Comment
Question by:Pachecda
  • 4
  • 4
10 Comments
 
LVL 5

Expert Comment

by:Atropa
ID: 18803627
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
0
 

Author Comment

by:Pachecda
ID: 18810163
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 ));
0
 
LVL 5

Expert Comment

by:Atropa
ID: 18810187
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")));
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:Pachecda
ID: 18810721
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.
0
 
LVL 5

Expert Comment

by:Atropa
ID: 18810747
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];
0
 

Author Comment

by:Pachecda
ID: 18811019
Hi Atropa,

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

Author Comment

by:Pachecda
ID: 18827041
HI Experts,

I was able to solve my problem above by using the Totals sigma sign and using  max value in DT_END
0
 
LVL 5

Expert Comment

by:Atropa
ID: 18827046
Oh yeah, that'll work too.  Leave it to the experts to over-complicate things!
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 21130188
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question