Solved

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

Posted on 2007-03-27
10
949 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:Pachecda
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 5

Expert Comment

by:Atropa
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now