Results 1 to 6 of 6
  1. #1
    Mantaii is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2011
    Posts
    21

    Convert finishing time to position

    Hi!
    Is it possible within a query to convert a time to a finishing position for a specific month.



    i.e.

    I have a runner who run 00:35:00 for a race in May
    I also have a running who runs the same race in May in 00:34:59

    Is there a way to put a position next to their name automatically so the second runner with 00:34:59 is allocated position 1 and the other runner is allocated position 2 etc.

    The reason I need to have a month and year is because the race is only ran once a month but I want to be able to print of reports for any year and month which will be stored in the database.

    Thanks,

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    I know you said 'query' - but - would a report work for you?

    In a report you can not only Group records by Month - but you can also create a 'Running Count' field that will give you your positions.

    If you Group your runs by Month and then sort by Timing [Ascending] - then the very first timing [the 'smallest' time] will have a running count [Position] of 1.

    I don't know if there is a way to do a running count in a query.
    If there is - I'd like to know it - because I'll probably find a use for it one of these days!

    In a query - the best I can think of right now is to sort by Month and then by Timing.
    You won't get the positions per se - but the fastest for each month will be the first one on the list for that month.

    I hope this helps.

  3. #3
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    I did a quick foray into 'Googledom' and found no query that would give you the position for each runner for each month.

    Another option that I would consider if it was something I was doing would be to write up a quick function with VBA to create the positions in each row of your data.
    Are you comfortable writing VBA code?

    If you MUST have a query then I am out of ideas.

  4. #4
    Mantaii is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2011
    Posts
    21
    Hey, thanks for the replies. It doesn't need to be a query, it could be a report. Its been quite some time since I worked with access so getting my head around it again is taking a bit of working out.
    I have done VBA coding as well but again, its been a while. Comfortable editing someone elses code to make it work for me but writing from scratch is another thing.

    Will look at reports again and see if I can get what you suggested.

    Thanks again!

  5. #5
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Mantaii View Post
    Hi!
    Is it possible within a query to convert a time to a finishing position for a specific month.
    Have you tried Googling "ranking query"? There are lots of posts on this since it is a common question.

    The ranking is determined by counting records outside some threshold. Here is a sample:

    SELECT
    p.KeyPct
    , (SELECT COUNT(*) FROM tblMiscPct WHERE KeyPct >= p.KeyPct) AS Rank
    FROM tblMiscPct AS p
    ORDER BY p.KeyPct DESC;

    Here "KeyPct" determines the order, highest value first. The second field ("Rank") is a
    subquery count of records that equal or exceed the current record's value (resulting in rank).

    *** And another method:

    First you have to create a module then paste this code to that new
    module

    Option Compare Database
    Dim CustID As Integer
    Dim ctr As Integer

    Function R(Id As Integer, intVal As Integer) As Integer
    If CustID <> Id Then
    ctr = 1
    CustID = Id
    Else
    ctr = ctr + 1
    End If
    R = ctr
    End Function

    Then use this query

    SELECT Territory, Potential,R(Territory, Potential) as rank
    FROM Table1
    ORDER BY Territory, Potential DESC;

    ------------------------------------
    These two examples are from this post:

    http://bytes.com/topic/access/answer...-records-query

  6. #6
    Mantaii is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2011
    Posts
    21
    Thanks! I went down the report option as it sorted everything perfectly. On with the next stage now and no-doubt I will be back looking for more answers. The problem I tend to find it not know what to google for.

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

Similar Threads

  1. Calculating race finishing positions
    By Coheeba in forum Queries
    Replies: 4
    Last Post: 09-01-2011, 12:44 PM
  2. Replies: 1
    Last Post: 08-07-2011, 07:58 AM
  3. Position of scroll bar
    By VictoriaAlbert in forum Access
    Replies: 2
    Last Post: 04-14-2011, 04:29 PM
  4. Replies: 1
    Last Post: 03-28-2011, 08:47 AM
  5. Convert local time to UTC
    By zapper222 in forum Programming
    Replies: 0
    Last Post: 08-01-2010, 03:01 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