Results 1 to 7 of 7
  1. #1
    mabuhay87 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    8

    HireDate with Different Dates in Employee

    Count the Employee having different hire date and show the lastest hire date to a new column.

    My table below:

    EmployeeNo HireDate TerminationDate

    11 1/1/2009 6/5/2009
    12 5/5/2009
    13 6/2/2009
    14 6/15/2009 11/1/2009
    15 7/1/2009
    11 9/8/2009
    14 2/5/2010

    The output should be like this:



    EmployeeNo-------- HireDate --------- TerminationDate-------------- RehireDate-(New Column)

    11 ------------------- 1/1/2009 ---------- 6/5/2009
    12 ------------------- 5/5/2009
    13 ------------------- 6/2/2009
    14 ------------------- 6/15/2009 ---------11/1/2009
    15 ------------------- 7/1/2009
    11------------------- 9/8/2009------------------------------------------------9/8/2009
    14 ------------------ 2/5/2010-------------------------------------------------2/5/2010

    Please help. Thanks.

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    Does following query helps ?
    Code:
    SELECT Table1.EmpID, Min(Table1.HireDate) AS MinOfHireDate as FirstHireDate, Max(Table1.HireDate) AS ReHireDate
    FROM Table1
    GROUP BY Table1.EmpID;
    change the field/table names for your case

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    probably don't want a double alias in that example amrut

    Code:
    SELECT Table1.EmpID, Min(Table1.HireDate) AS FirstHireDate, Max(Table1.HireDate) AS ReHireDate FROM Table1 GROUP BY Table1.EmpID;

  4. #4
    mabuhay87 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    8
    Rehire Date field should not be showing the first hire date, it should be blank. Only showing the Rehire Date record.

    Please help. Thanks.

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    can I ask what you're trying to do with this query because what you're asking for in your original example doesn't really make sense to me. If you're trying to create a report or query with hire/termination history there are better ways to do this, if you're trying to indicate whether or not someone was a rehire on their most recent record there's an easier way to do that too.

  6. #6
    mabuhay87 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    8
    Can you please give an examples the best way to do it? I want the history of hire/termination.
    Thank you for your help.

  7. #7
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Code:
    SELECT EmployeeNo, HireDate, TerminationDate FROM TABLENAME ORDER BY EmployeeNo, HireDate
    This will sort your date FIRST by employee, SECOND by Hire Date, so your most recent hire will show LAST, if you want to show their most recent hire FIRST you would do

    Code:
    SELECT EmployeeNo, HireDate, TerminationDate FROM TABLENAME ORDER BY EmployeeNo, HireDate DESC

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Indexing (no dupes) dates where employee code = XXXX
    By snipe in forum Database Design
    Replies: 4
    Last Post: 12-12-2013, 03:19 PM
  2. Replies: 8
    Last Post: 12-02-2013, 03:46 PM
  3. Replies: 1
    Last Post: 10-18-2013, 03:14 PM
  4. Replies: 8
    Last Post: 06-06-2012, 12:28 PM
  5. Query input dates for range of dates in two fields
    By kagoodwin13 in forum Queries
    Replies: 3
    Last Post: 02-13-2012, 04:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums