Results 1 to 5 of 5
  1. #1
    valbor is offline Novice
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Location
    NY
    Posts
    6

    Number of concurrent users


    I have a table which provides SessionId, SessionStartDate and SessionEndDate. How to create a query to determine max number of concurrent sessions each day?

  2. #2
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    Well first you need the date being inspected. Call this the CheckDate. Then you need to compare whether StartDate is <= CheckDate AND EndDate is >= CheckDate

    Get this first query to return all the records correctly.

    Then make a second query using the first query as its source, and make it an Aggregate Query (epsilon E in toolbar/ribbon) - set to count records.

    An Access textbook will have examples of these tasks.

    Hope this helps.

  3. #3
    valbor is offline Novice
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Location
    NY
    Posts
    6
    Thanks for the reply. This approach will provide me with the total number of sessions per day. What I'm looking for is MAX number of concurrent sessions daily. For example, session A started at 1:03:01 and ended at 1:55:00; session B started at 1:55:03 and ended at 2:05:00; session 3 started at 3:04 and ended at 4:05. Total number of sessions is 3, but max of concurrent sessions is 2 - only 2 sessions (A and B) overlap.

  4. #4
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    You would have to craft a custom sql statement with a self join defined by overlapping times. Nothing vanilla embedded into Access has this type solution. Too complicated for me to attempt to do off the cuff.

  5. #5
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you can write code to scan the table, count the "online" users, save the max number while scaning. do forget the sessions start before this date and still active.
    Sample code:
    Code:
    Public Function Maxconcurrent(dDate As Date)
        Dim rs As dao.Recordset
        Dim maxcount, curcount As Long
        Set rs = CurrentDb.OpenRecordset("SELECT id,sessionTable.sessionStart, 'start' as ev FROM sessionTable where format(sessionstart, 'yyyymmdd')='" & Format(dDate, "yyyymmdd") & "' UNION SELECT id,sessionTable.sessionend, 'end' as ev FROM sessionTable where format(sessionend, 'yyyymmdd')='" & Format(dDate, "yyyymmdd") & "' ORDER BY sessionStart")
        maxcount = 0
        curcount = 0
        Do While Not rs.EOF
            If rs!ev = "start" Then
                curcount = curcount + 1
                If curcount > maxcount Then maxcount = curcount
            Else
                curcount = curcount - 1
            End If
            rs.MoveNext
        Loop
        Set rs = Nothing
        ' plus session start before this date and end in/after this date or null
        Maxconcurrent = maxcount + DCount("*", "sessiontable", "format(sessionstart, 'yyyymmdd') < '" & Format(dDate, "yyyymmdd") & "' and ( format(sessionend, 'yyyymmdd') >= '" & Format(dDate, "yyyymmdd") & "' or (sessionEnd is null))")
    End Function

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

Similar Threads

  1. Multiple Users
    By Nettie in forum Access
    Replies: 5
    Last Post: 10-15-2010, 02:47 PM
  2. How to Boot off users
    By neishock in forum Access
    Replies: 2
    Last Post: 10-11-2010, 02:07 PM
  3. Making New Record Number Next Numerical Number
    By jhillbrown in forum Access
    Replies: 1
    Last Post: 03-10-2010, 11:06 AM
  4. How to have multiple users
    By Eric1066 in forum Access
    Replies: 5
    Last Post: 11-19-2009, 05:14 AM
  5. Sum Of Positive Number and Negative Number
    By maysamab in forum Reports
    Replies: 1
    Last Post: 10-20-2008, 04:06 PM

Tags for this Thread

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