Results 1 to 2 of 2

Thread: Displaying a query

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2006
    Posts
    977

    Displaying a query

    Hi

    I am new to crystal reports and I want to display the result of a query executed in VB6 in crystal report.
    the query is:
    sql = "Select Top 20 PersonID From Member Group By PersonID Order By COUNT(*) DESC"

    this query displays the top 20 persons who occur the most in the table Member.
    Can anyone guide me through the steps to display my query?

    Thanks in advance

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2006
    Posts
    977

    Re: Displaying a query

    I am using VB6, Crystal report 9 and SQL server 2000.

    I want to display the top 20 Persons in a chart,the full code I used to see who are the Top 20 persons who occur the most in the table Member:

    VB Code:
    1. Private Sub cmdshow_Click()
    2. Dim sdate1 As Date
    3. Dim sdate2 As Date
    4. Dim sql As String
    5.  
    6. List1.Clear
    7. sdate1 = Format(DTPicker1.Value, "Medium Date")
    8. sdate2 = Format(DTPicker2.Value, "Medium Date")
    9.  
    10. sql = "Select Top 20 PersonID From Member inner Join Article on Member.ArticleID=Article.ArticleID where PDate between '" & sdate1 & "' and '" & sdate2 & "' Group By PersonID Order By COUNT(*) DESC"
    11.  
    12. Rs.Open sql, cnn, adOpenStatic, adLockOptimistic
    13. Rs.MoveFirst
    14. Do While Not Rs.EOF
    15. Rs2.Open "Select * from Person where PersonID=" & Rs!PersonID, cnn, adOpenStatic, adLockOptimistic
    16. sPerson = Rs2!PersonName
    17. Rs2.Close
    18.  
    19. Rs1.Open "Select count(*) from Member inner Join Article on Member.ArticleID=Article.ArticleID where PDate between '" & sdate1 & "' and '" & sdate2 & "' and KeyID= " & Rs!PersonID, cnn, adOpenStatic, adLockOptimistic
    20. nocc = Rs1(0)
    21. Rs1.Close
    22. ssPerson = sPerson& "-" & nocc
    23.  
    24. List1.AddItem ssPerson
    25. Rs3.MoveNext
    26. Loop
    27. Rs3.Close
    28. End Sub
    The above code display in a listbox the Top 20 PersonName with their number of occurences.

    e.g the listbox looks like:

    John Smith- 2365 occurences
    Sandra Lopez- 1595 occurences
    ...

    What I want is generate a crystal report containing a chart that displays each PersonName and it's corresponding graph.(depending on his number of occurences)

    I am new to crystal report so can anyone guide me?

    Thanks in advance

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