473,395 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problems sorting dates in a query

44
I am working on a query that will sort all employees that have been hired after a certain date and have not been terminated within a certain date. (Hope this doesn't sound too complicated!) I am working on September statement: which means that i need the query to spit out employees hired before 07/01/07, but not to include them if they have a termination date earlier than 08/31/2007. What I have so far is:
HAVING (((EMPLOYEES.[HIRE DATE]) Between #1/1/1972# And [Hires thru what date?]) AND ((EMPLOYEES.SECTION)=[What Section?]) AND ((EMPLOYEES.[VLIFE DEDUCTION])<>0)) OR (((EMPLOYEES.[TERMINATION DATE])>[Terminations thru what date?]))
ORDER BY EMPLOYEES.LAST, EMPLOYEES.FIRST, EMPLOYEES.MIDDLE;
Sep 27 '07 #1
7 2135
I am working on a query that will sort all employees that have been hired after a certain date and have not been terminated within a certain date. (Hope this doesn't sound too complicated!) I am working on September statement: which means that i need the query to spit out employees hired before 07/01/07, but not to include them if they have a termination date earlier than 08/31/2007. What I have so far is:
HAVING (((EMPLOYEES.[HIRE DATE]) Between #1/1/1972# And [Hires thru what date?]) AND ((EMPLOYEES.SECTION)=[What Section?]) AND ((EMPLOYEES.[VLIFE DEDUCTION])<>0)) OR (((EMPLOYEES.[TERMINATION DATE])>[Terminations thru what date?]))
ORDER BY EMPLOYEES.LAST, EMPLOYEES.FIRST, EMPLOYEES.MIDDLE;
Zulema
The user could enter the date as 1/1/2007 or 01/01/2007 so the dates need to be set to a consistant format: Format([hire date],"mm/dd/yyyy" This would apply to your parameter fields as well.

Hope this helps.
Sep 27 '07 #2
mlcampeau
296 Expert 100+
I am working on a query that will sort all employees that have been hired after a certain date and have not been terminated within a certain date. (Hope this doesn't sound too complicated!) I am working on September statement: which means that i need the query to spit out employees hired before 07/01/07, but not to include them if they have a termination date earlier than 08/31/2007. What I have so far is:
Expand|Select|Wrap|Line Numbers
  1. HAVING (((EMPLOYEES.[HIRE DATE]) Between #1/1/1972# And [Hires thru what date?]) AND ((EMPLOYEES.SECTION)=[What Section?]) AND ((EMPLOYEES.[VLIFE DEDUCTION])<>0)) OR (((EMPLOYEES.[TERMINATION DATE])>[Terminations thru what date?]))
  2. ORDER BY EMPLOYEES.LAST, EMPLOYEES.FIRST, EMPLOYEES.MIDDLE;
Try this:
Expand|Select|Wrap|Line Numbers
  1. HAVING (([Employees.HireDate] Between #1/1/1972# AND (CDate([Hires thru what date?]))) AND [Employees.Section]=[What Section?] AND [Employees.VLife Deduction]<>0 AND ([Employees.TerminationDate] Is Null OR [Employees.TerminationDate]>CDate([Terminations thru what date?])))
Sep 27 '07 #3
Zulema
44
Zulema
The user could enter the date as 1/1/2007 or 01/01/2007 so the dates need to be set to a consistant format: Format([hire date],"mm/dd/yyyy" This would apply to your parameter fields as well.

Hope this helps.
I need it to list all records with hire dates up to a certain date, but to disregard the record if the record has a termination date earlier than the date the user inputs when prompted....hope this makes sense!
Sep 27 '07 #4
Zulema
44
My query looks like this:dateststqry

SELECT EMPLOYEES.[HIRE DATE], EMPLOYEES.SECTION, EMPLOYEES.[TERMINATION DATE], Last(EMPLOYEES.LAST) AS LastOfLAST, EMPLOYEES.FIRST
FROM EMPLOYEES
GROUP BY EMPLOYEES.[HIRE DATE], EMPLOYEES.SECTION, EMPLOYEES.[TERMINATION DATE], EMPLOYEES.FIRST, NZ([TERMINATION DATE])
HAVING (((EMPLOYEES.[HIRE DATE])<=[THRU WHAT HIRE DATE?]) AND ((NZ([TERMINATION DATE]))<=#9/30/2007#))
ORDER BY Last(EMPLOYEES.LAST), EMPLOYEES.FIRST;

results:
HIRE DATE SECTION TERMINATION DATE LastOfLAST FIRST
1/1/1991 Admin 6/30/2007 Last First
11/19/2001 Admin 10/18/2007 Last First
03/2/1999 Admin Last First
09/13/2007 Admin Last First
I need it to exclude the rows with termination dates, but not if the termination date is later than the date that the user enters when prompted for a date....
Sep 27 '07 #5
mlcampeau
296 Expert 100+
My query looks like this:dateststqry

Expand|Select|Wrap|Line Numbers
  1. SELECT EMPLOYEES.[HIRE DATE], EMPLOYEES.SECTION, EMPLOYEES.[TERMINATION DATE], Last(EMPLOYEES.LAST) AS LastOfLAST, EMPLOYEES.FIRST
  2. FROM EMPLOYEES
  3. GROUP BY EMPLOYEES.[HIRE DATE], EMPLOYEES.SECTION, EMPLOYEES.[TERMINATION DATE], EMPLOYEES.FIRST, NZ([TERMINATION DATE])
  4. HAVING (((EMPLOYEES.[HIRE DATE])<=[THRU WHAT HIRE DATE?]) AND ((NZ([TERMINATION DATE]))<=#9/30/2007#))
  5. ORDER BY Last(EMPLOYEES.LAST), EMPLOYEES.FIRST;
results:
HIRE DATE SECTION TERMINATION DATE LastOfLAST FIRST
1/1/1991 Admin 6/30/2007 Last First
11/19/2001 Admin 10/18/2007 Last First
03/2/1999 Admin Last First
09/13/2007 Admin Last First
I need it to exclude the rows with termination dates, but not if the termination date is later than the date that the user enters when prompted for a date....
Zulema,
Did you try my suggestion in Post#3? If so, what were the results? Here's my suggestion again, incorporated into your entire sql statement (in the future please wrap your code in Code tags by highlighting the code, and clicking on the button with the # sign)

Expand|Select|Wrap|Line Numbers
  1. SELECT EMPLOYEES.[HIRE DATE], EMPLOYEES.SECTION, EMPLOYEES.[TERMINATION DATE], Last(EMPLOYEES.LAST) AS LastOfLAST, EMPLOYEES.FIRST
  2. FROM EMPLOYEES
  3. GROUP BY EMPLOYEES.[HIRE DATE], EMPLOYEES.SECTION, EMPLOYEES.[TERMINATION DATE], EMPLOYEES.FIRST, 
  4. HAVING HAVING (([Employees.HireDate]<=(CDate([Hires thru what date?]))) AND [Employees.Section]=[What Section?] AND [Employees.VLife Deduction]<>0 AND ([Employees.TerminationDate] Is Null OR [Employees.TerminationDate]>CDate([Terminations thru what date?])))
  5. ORDER BY Last(EMPLOYEES.LAST), EMPLOYEES.FIRST;
Sep 27 '07 #6
Zulema
44
It worked!!! Thank you very much!
Sep 28 '07 #7
mlcampeau
296 Expert 100+
Glad you got it working!
Sep 28 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: bissatch | last post by:
Hi, I am about to write an application that will display all pdf files in a folder and display them by file name in order of date. Is there an easy way of doing this? I was thinking about...
1
by: John Taylor | last post by:
I have a ListCtrl with 5 columns. The first 4 columns are either strings or integers, but the last column is a string in the format of MM-DD-YYYY. I searched google and also read over the...
4
by: Russell | last post by:
I'm having a fit with a query for a range of dates. The dates are being returned from a view. The table/field that they are being selected from stores them as varchar and that same field also...
22
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b)...
18
by: Scott | last post by:
I have a collection where the items in the collection are dates. I want to iterate over the collection and build a value list string for the rowsource of a listbox. The dates in the collection are...
9
by: Neil | last post by:
I have been coding with ASP for some time now. I am using an ACCESS database. I am in the UK and wish to use DD/MM/YYYY format for dates. I have had no end of problems and possible solutions to...
3
by: melanieab | last post by:
Hi, When you click on a column header to sort in ascending or descending order, numbers (and dates) aren't sorted correctly. It turns up like this: 1 10 11 2 3 4
34
mkuberski
by: mkuberski | last post by:
I have a database with 3 tables, Mailing_List, All_Seminars and Proximity_Results. The Mailing_List is a list of customers and their address, All_Seminars is a list of seminar locations and the...
0
by: daverskully | last post by:
I REALLY REALLY appreciate any help that anyone can offer. I have a table called Data with the following fields: 1) ID 2) ReportDate 3) Department 4) DepartmentNumber 5) AccountExecutive...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.