Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-03-27
10
Medium Priority
?
960 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

610 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