Results 1 to 14 of 14
  1. #1
    ClareMoore is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    8

    Help with MAX date

    I have a table that looks like

    event_id, activity_name, operator_name, start_date, end_date

    I want to select all columns, and select an extra column which contains the LAST end_date value from the whole table. I'd expect this column to contain the same value in each row, which is the latest date



    can you help?

  2. #2
    Rixxe is offline Blessed Bear
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Location
    London (Essex ... yep!)
    Posts
    184
    This might be helpful:
    http://techonthenet.com/sql/max.php


    Post your code if you get stuck, sure someone here can help you.

  3. #3
    ClareMoore is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    8

    Here is my code:

    Hi there and thanks

    i'd already looked at that page but i'm still not getting the results i need

    I tried:

    SELECT start, end, MAX(end) as MaxEnd
    FROM mw_activity_data
    group by start, end

    But the maxend getting returned is just the end from each row, i want this last column to be the maximum end from teh whole table repeated

    Thanks

  4. #4
    ClareMoore is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    8
    The results i'm getting look like:

    start end MaxEnd
    26/01/2011 6:00:00 AM 26/01/2011 6:00:30 AM 26/01/2011 6:00:30 AM
    26/01/2011 6:00:30 AM 26/01/2011 6:03:58 AM 26/01/2011 6:03:58 AM
    26/01/2011 6:03:58 AM 26/01/2011 6:21:45 AM 26/01/2011 6:21:45 AM
    26/01/2011 6:21:45 AM 26/01/2011 6:25:45 AM 26/01/2011 6:25:45 AM

    which is not what i want

  5. #5
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    So you want
    26/01/2011 6:00:00 AM 26/01/2011 6:00:30 AM 26/01/2011 6:25:45 AM
    26/01/2011 6:00:30 AM 26/01/2011 6:03:58 AM 26/01/2011 6:25:45 AM
    26/01/2011 6:03:58 AM 26/01/2011 6:21:45 AM 26/01/2011 6:25:45 AM
    26/01/2011 6:21:45 AM 26/01/2011 6:25:45 AM 26/01/2011 6:25:45 AM

    ?

  6. #6
    ClareMoore is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    8
    Yes exactly, do you know how i go about achieving this?

    Thanks very much

  7. #7
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    Why would you want to store that in a table? That's something that you would query for on the fly when its needed.

  8. #8
    ClareMoore is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    8
    I am writing a query ......
    the results i just said i wanted are what i want FROM my query?

    The table looks like:

    start end
    26/01/2011 6:00:00 AM 26/01/2011 6:00:30 AM
    26/01/2011 6:00:30 AM 26/01/2011 6:03:58 AM
    26/01/2011 6:03:58 AM 26/01/2011 6:21:45 AM
    26/01/2011 6:21:45 AM 26/01/2011 6:25:45 AM

    I need help writing a query that will select start, end and MaxEnd, giving the results i posted above

  9. #9
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    You can get the max end time but it wont simply populate a full column in a query.

    I can see you wanting to pull the max time
    SELECT max(End) As MaxEnd
    FROM myTable;

    I can also see you wanting to pull the record that contains the max time
    SELECT Top 1 *
    FROM myTable
    ORDER BY End DESC;

    I dont see, however, why you would want all the of records and an extra column that contains the max. Also, my apologies about the table assumption. I figured thats where you were going with it.

  10. #10
    ClareMoore is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    8
    Because I'm experimenting with creating a report in SQL Server Reporting services, using a third party chart control, and it would make my life a lot easier if i could have this coming back with the dataset.

    Does that mean it cant be done?

  11. #11
    ClareMoore is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    8
    I can only have one dataset per report using this third party tool, which is why i was hoping ot append the MAX to a separate column

  12. #12
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    You would have to store it in another table as I cant think of a way to pull it with one query.

    you would create a SELECT query that holds the maxEnd. Then use an update query to update a blank field MaxEndDate with DLookup("maxEnd", "queryName")

  13. #13
    ClareMoore is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    8
    I think i figured it out, but i had to use an extra field, machine_id in my query, sorry i shoud have added that to my example at the beginning

    SELECT
    STT.FirstBegin,
    STT.FinalEnd,
    *
    FROM mw_activity_data
    INNER JOIN (
    SELECT mach_id,
    min(start) as FirstBegin,
    max(end) as FinalEnd
    FROM mw_activity_data
    GROUP BY mach_id
    ) STT ON mw_activity_data.mach_id = STT.mach_id
    ORDER BY STT.mach_id,
    start

  14. #14
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    As long as you got it working, nothing else really matters.
    Cheers!

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

Similar Threads

  1. Replies: 1
    Last Post: 07-07-2010, 04:22 PM
  2. Set date field on subform to date variable
    By laavista in forum Access
    Replies: 4
    Last Post: 06-30-2010, 06:32 PM
  3. set date field on form to date variable
    By laavista in forum Access
    Replies: 3
    Last Post: 06-28-2010, 03:03 AM
  4. Replies: 2
    Last Post: 07-31-2009, 06:56 AM
  5. Replies: 1
    Last Post: 12-09-2005, 10:29 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