?
Solved

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

Posted on 2007-03-27
10
Medium Priority
?
957 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
[X]
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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

770 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