Results 1 to 3 of 3

Thread: Multiple counts ... (DBase's)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Oporto, Portugal
    Posts
    134

    Post

    I'm ,

    I'm making a DB app to an hospital and there is a question that is intrigging me.

    I've to make a report (currently using Crystal RDC 6.0) with the amount of exams (severall kinds of exams) made by a department. The DB only gives me the exams by patient so I've to make an SQL like:

    SQL = "Select * from tableX WHERE exam = '" & examKind & "' AND department = '" & departmentName & "'"

    There are many kinds of exams so I need to do serveral re-calls of that SQL (it takes me to long. Is there an easy way ? I've tried:

    SQL = "SELECT * from tablex WHERE department = '" & departmentName & "'"

    and from there count record by record (rs.movenext) the kind of exam and add it to an array. TOO SLOW ...


    Is there a simpler way ?

    I know that every time in the past something like this appened to me there was allways a simpler way...

    Thank in advance,

    ------------------
    Jorge Ledo
    [email protected]
    Portugal

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Why don't you Group the Results by Exam and use the COUNT() Function, then you can easily return the Exam Name and How many Times a Specified Department Took that Exam very easily, ie.

    SQL = "SELECT Exam, COUNT(Exam) As [Times Taken] FROM TableX WHERE Department = '" & sDepartment & "' GROUP BY Exam"



    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Oporto, Portugal
    Posts
    134

    Post

    It turned out as a much complex task.
    It was solved by this SQL statment:

    sql = "SELECT inscricoes.nr_inscricao, inscricoes_exames.cod_inscricao, inscricoes_exames.cod_exame, inscricoes.cod_entidade, utentes.cod_posto_clinico, inscricoes.data
    FROM postos_clinicos INNER JOIN (utentes INNER JOIN (inscricoes INNER JOIN inscricoes_exames ON inscricoes.nr_inscricao = inscricoes_exames.cod_inscricao) ON utentes.codigo = inscricoes.cod_utente) ON postos_clinicos.codigo = utentes.cod_posto_clinico
    WHERE (((inscricoes_exames.cod_exame)=" & ExamType & ") AND ((utentes.cod_posto_clinico)= " & DepartmentName & ") AND ((inscricoes.data)> " & BeginDate & " And (inscricoes.data)< " & EndDate & "));"

    But thank you very much Aaron your reply helped me to understand the COUNT statment.

    Thank you,



    ------------------
    Jorge Ledo
    [email protected]
    Portugal

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