J
Joel Maxuel
I am working on a query for one of my reports. It takes a percentage of
selected diagnoses (and some diagnosis groups). To save the number of
queries, I have nested a SQL statement for each diagnosis (diagnosis group).
For a single diagnosis, I use the following expression:
Primary Dx Schizoaffective Disorder: ((SELECT
Count([qryuAxisIDiag].[DiagValue]) AS Count FROM [qryuAxisIDiag] WHERE
((([qryuAxisIDiag].[DiagDetail])="Schizoaffective Disorder")))/[Total Number
of Clients.CountOfGender])
For a diagnosis group, I use:
Primary Dx PD: ((SELECT Sum([qrygAxisDxPD].[DxCount]) FROM
[qrygAxisDxPD])/[Total Number of Clients.CountOfGender])
Which links to another query with the following:
SELECT qryuAxisIDiag.ID, IIf(Count([DiagValue])>0,1,0) AS DxCount
FROM qryuAxisIDiag
WHERE (((qryuAxisIDiag.DiagValue)="Personality Disorder"))
GROUP BY qryuAxisIDiag.ID;
Note that I use the IIf(Count([DiagValue])>0,1,0) as (in this case) a
patient may have multiple personality disorders, but want to return that a
personality disorder is present. Also, qryuAxisIDiag is a union query
listing all diagnoses for each patient.
In total, there are 26 fields in this query and have found that it runs very
slow and often get the "Cannot open any more databases" error. At that point
I will have to close and reopen the database. Design view of the report is
horribly slow as well *(and sometimes cannot find the controlsource of the
fields while in design view).
I was hoping to simplify the query, by using Sum() and mathematical
expressions instead of the nested SQL statements, but I would get the
following error message:
"You tried to execute a query that does not include the specified expression
'Sum(Iif(>0,1,0))/[CountOfGender]' as part of an aggregate function."
Short of creating dozens of additional queries to break up the calculation
(which I want to avoid), any ideas on fixing this problem?
selected diagnoses (and some diagnosis groups). To save the number of
queries, I have nested a SQL statement for each diagnosis (diagnosis group).
For a single diagnosis, I use the following expression:
Primary Dx Schizoaffective Disorder: ((SELECT
Count([qryuAxisIDiag].[DiagValue]) AS Count FROM [qryuAxisIDiag] WHERE
((([qryuAxisIDiag].[DiagDetail])="Schizoaffective Disorder")))/[Total Number
of Clients.CountOfGender])
For a diagnosis group, I use:
Primary Dx PD: ((SELECT Sum([qrygAxisDxPD].[DxCount]) FROM
[qrygAxisDxPD])/[Total Number of Clients.CountOfGender])
Which links to another query with the following:
SELECT qryuAxisIDiag.ID, IIf(Count([DiagValue])>0,1,0) AS DxCount
FROM qryuAxisIDiag
WHERE (((qryuAxisIDiag.DiagValue)="Personality Disorder"))
GROUP BY qryuAxisIDiag.ID;
Note that I use the IIf(Count([DiagValue])>0,1,0) as (in this case) a
patient may have multiple personality disorders, but want to return that a
personality disorder is present. Also, qryuAxisIDiag is a union query
listing all diagnoses for each patient.
In total, there are 26 fields in this query and have found that it runs very
slow and often get the "Cannot open any more databases" error. At that point
I will have to close and reopen the database. Design view of the report is
horribly slow as well *(and sometimes cannot find the controlsource of the
fields while in design view).
I was hoping to simplify the query, by using Sum() and mathematical
expressions instead of the nested SQL statements, but I would get the
following error message:
"You tried to execute a query that does not include the specified expression
'Sum(Iif(>0,1,0))/[CountOfGender]' as part of an aggregate function."
Short of creating dozens of additional queries to break up the calculation
(which I want to avoid), any ideas on fixing this problem?