Results 1 to 3 of 3

Thread: SQL Statement???

  1. #1

    Thread Starter
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565

    Question

    I have a table called Work_History and in it a field called Work_Date.

    How can I get hold of the Work_Date which occurs most often?

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Question This will work, but it is not too efficient

    Try this code on for size:
    -------------------------------------------------------
    Dim CurrentDate As Date
    Const StartDate = "01/01/1997"
    Dim EndDate As Date
    Dim rs As Recordset
    Dim MaxCount As Integer
    Dim MaxDate As Date
    MaxCount = 0
    EndDate = Date
    For CurrentDate = StartDate To EndDate

    csql = "SELECT count(Work_Date) as expcount FROM Work_History where Work_Date ='" & CurrentDate & "'"
    On Error Resume Next
    rs.Close
    On Error GoTo 0

    rs.Open csql, Database
    If rs.EOF = False Then
    If rs.Fields("expcount") > MaxCount Then
    MaxDate = CurrentDate
    MaxCount = rs.Fields("expcount")
    End If
    End If

    Next
    -------------------------------------------------------


    Hope this helps

  3. #3

    Thread Starter
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    I know how to do it now :

    Code:
    SELECT COUNT(Work_Date), Work_Date 
    FROM Work_History GROUP BY Work_Date 
    ORDER BY COUNT(Work_Date) DESC
    Cheers for the inout anyway.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width