Results 1 to 5 of 5

Thread: Counting....

  1. #1

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396

    Counting....

    If I want to Count the number of times something occurs in a Table how do I do that...

    I could do with the Recordcount property to get a total figure. For example

    If a following table exists:
    A
    A
    A
    A
    B
    B
    C
    D
    D

    How do I know how many times does A exists and so on....
    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

  2. #2
    Addicted Member
    Join Date
    Jul 2002
    Posts
    234
    Well, I don't use Microsoft's implementation of SQL, but on MySQL, the following would do what you are looking for:

    Select count(*) from Table where row1="A"

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Code:
    SELECT Count(SomeField) As RowCount WHERE SomeField="A"
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  4. #4

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    Thanks crptcblade
    Can it be counted without doing an SQL statement? Is it possible to do it programatically???
    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

  5. #5
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    What do you mean by 'to do it programatically'? The sql statement is the better way to do it. But you can open your table and then loop through it to count A's , B's and other. In that case this will take much longer to count it.

    VB Code:
    1. Dim countA, countB, countC
    2.  
    3. countA=0
    4. countB=0
    5. countC=0
    6.  
    7. Do Until rs.EOF
    8.   Select Case rs("YourFieldName")
    9.      Case "A"
    10.         countA=countA+1
    11.      Case "B"
    12.         countB=countB+1
    13.      Case "C"
    14.         countC=countC+1
    15.    End Select
    16.    rs.MoveNext
    17. Loop

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