Solved

Access 2003 Query return values that have

Posted on 2010-09-10
10
397 Views
Last Modified: 2013-11-28
I am trying to create a query in MS Access to display users with training dates that are going to expire within 1 week (trainings expire a year from previous training date).  I am familiar with Oracle's date function and using truncate, however I am having issues finding the equivalent in MS Access.


SELECT Employees.Last_Name, Employees.First_Name, Employees.Dept, Employees.Last_Training_Date, Employees.Notes
FROM Employees
WHERE (([Last_Training_Date]< "yyyy", -1, Date()));
0
Comment
Question by:singi007
[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
  • 2
10 Comments
 
LVL 1

Expert Comment

by:NEVAEHSIN
ID: 33648540
You can try...

[Last_Training_Date]<=DateAdd("yyyy", -1, Date)
0
 

Author Comment

by:singi007
ID: 33648770
It says "Data type mismatch in criteria expression" and I think that would just get me 1 year past, I need it to give me the users that are within 1 week of a year past due.
0
 
LVL 1

Expert Comment

by:NEVAEHSIN
ID: 33648898
First off - is [Last_Training_Date] Date/Time format?

Next try....
 where DateAdd("yyyy",1,Last_Training_date)>DateAdd("d",-7,Date());
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33648905
Catches those who are both overdue, and who have a week left:


SELECT Employees.Last_Name, Employees.First_Name, Employees.Dept, Employees.Last_Training_Date, Employees.Notes
FROM Employees
WHERE DateAdd("yyyy", -1, DateAdd("d", -7, Date())) <= [Last_Training_Date])

Open in new window

0
 

Author Comment

by:singi007
ID: 33661520
Yes, Last_Training_Date is a Date/Time format. The syntax

WHERE DateAdd("yyyy", -1, DateAdd("d", -7, Date())) >= [Last_Training_Date]

gives me those that are both overdue and who have a week left, but I want to differentiate between the two. Is it possible to break it into 2 queries? or some other method of displaying the 2 different groups?
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33662003
Give this a try:
SELECT Employees.Last_Name, Employees.First_Name, Employees.Dept, Employees.Last_Training_Date, Employees.Notes,
    IIf(DateAdd("yyyy", 1, [Last_Training_Date]) > Date(), "Overdue", "Expiring Soon") AS Status
FROM Employees
WHERE DateAdd("yyyy", -1, DateAdd("d", -7, Date())) <= [Last_Training_Date])

Open in new window

0
 

Author Comment

by:singi007
ID: 33664877
Ok, I think from your solution I figured out how to get and differentiate the overdue employees and the overdue in the next 7 days employees. Is there anyway to use this IIf function to differentiate between 3 sets, for example the overdue employees, employees 7 days from being overdue and 6 weeks from being overdue? or does the IIf function only allow 2?
SELECT Employees.Last_Name, Employees.First_Name, Employees.DEPT, Employees.Last_Training_Date, Employees.Notes,
IIf(DateAdd("d", 365 , [Last_Training_Date]) < Date(), "Overdue", "Expiring within 7 Days") AS Status
FROM Employees
WHERE ( DateAdd("d", -358, Date())) >= [Last_Training_Date]
order by Last_Training_Date;

Open in new window

0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 125 total points
ID: 33665202
singi007,We're starting to get kind of far afield now with the follow-ups.  Your original question has been answered, and so I think it's time to close this.  One more for the road, see below.This uses the Switch function.  You could use embedded IIfs, but I prefer not to.  Please see my article on the subject:http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_3556-Using-the-Switch-Function-in-Microsoft-Access.htmlPatrick
SELECT Last_Name, First_Name, DEPT, Last_Training_Date, Notes,
Switch(DateAdd("d", 365, [Last_Training_Date]) < Date(), "Overdue", DateDiff("d", Date(), DateAdd("yyyy", 1, [Last_Training_Date])) <7, "Due within 7 days", True, "Due in 8-42 Days") AS Status
FROM Employees
WHERE DateAdd("d", 42, (DateAdd("yyyy", -1, Date()))) >= [Last_Training_Date]
order by Last_Training_Date;

Open in new window

0
 

Author Comment

by:singi007
ID: 33665319
Thank you! This is exactly what I was trying to figure out. I thought it would be easy to figure out the rest once I had the first part, but then realized it wasn't as simple as I had hoped.
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33665397
singi007,Glad to help!  If you have not already done so, I would really appreciate it if you could please return to my articlehttp://www.experts-exchange.com/Microsoft/Development/MS_Access/A_3556-Using-the-Switch-Function-in-Microsoft-Access.htmland click 'Yes' for the 'Was this helpful?' voting.matthewspatrick
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql query help 15 55
Sql case statement to calculate totals 5 37
get and set file atrributes 5 13
Access lists formating 8 18
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

730 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