?
Solved

Access only runs on one processor?

Posted on 2012-09-11
5
Medium Priority
?
352 Views
Last Modified: 2012-09-11
I was running this query today and my PC was freaking out!

SELECT Patient.PatientID, Patient.VisitID, Patient.AdmitDateTime, (select max([AdmitDateTime]) from Patient P where P.PatientID=Patient.PatientID and P.AdmitDateTime<Patient.AdmitDateTime) AS PrevAdmissionDate, DateDiff("d",[PrevAdmissionDate],[AdmitDateTime]) AS AdmissonDiff, Patient.DischargeDateTime,(select max([DischargeDateTime]) from Patient P where P.PatientID=Patient.PatientID and P.DischargeDateTime<Patient.DischargeDateTime) AS PrevDischargeDate, DateDiff("d",[PrevDischargeDate],[DischargeDateTime]) AS DischargeDiff
FROM Patient
ORDER BY Patient.PatientID, Patient.AdmitDateTime;

The query ran for 30 minutes.  

The CPU was maxed out and the RAM was all used up.  I learned that Access only runs on one of the 4 CPUs I have.  Is this right?  Seems crazy that my PC can handle so much and it doesn't utilize the full system.  Please let me know what I can do to speed up queries like this.
0
Comment
Question by:Scotto123
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:bharrington83
ID: 38387757
What version are you using?
0
 
LVL 9

Accepted Solution

by:
bharrington83 earned 2000 total points
ID: 38387758
Actually that doesn't matter. Access does not support multi threading.  Consider using SQL Express which does.
0
 

Author Comment

by:Scotto123
ID: 38387780
I have Access 2010.  I could run the data in SQL Server Mgt Studio.  I am anayzing data and want to be able to do it easier without having to build SQL tables and such.  Maybe I should change my analysis style.
0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 38387855
It's your nested select statements that are causing the problem.

Try creating a query like this:

SELECT N.PatientID, N.AdmitDateTime, Max(P.AdmitDateTime) as PrevAdmit, Max(P.DischargeDateTime) as PrevDischarge
FROM Patients N
LEFT JOIN Patients P
ON N.PatientID = P.PatientID
AND P.DischargeDateTime < N.AdmitDateTime
GROUP BY N.PatientID, N.AdmitDateTime

That should give you every PatientID, Admission, and the patients most recent previous admission and discharge.  If that works, then use that as a subquery and join it to your Patients table on PatientID and AdmitDateTime to get the other fields you need from the Patients table.

But do you really need every patient/admit combination?  If not you could limit the results of this query significantly by adding a WHERE clause on the N.AdmitDateTime field.  Or by minimizing the number of records in the N part of the query by using something like:

SELECT N.PatientID, N.AdmitDateTime, Max(P.AdmitDateTime) as PrevAdmit, Max(P.DischargeDateTime) as PrevDischarge
FROM (SELECT PatientID, MAX(AdmitDateTime) as MostRecentVisit FROM Patients) as N
LEFT JOIN Patients P
ON N.PatientID = P.PatientID
AND P.DischargeDateTime < N.MostRecentVisit
GROUP BY N.PatientID, N.AdmitDateTime

By using the subquery in this, you limit N to one record per patient, and the resulting recordset, with the PrevAdmit and PrevDischarge will only contain one record as well.
0
 

Author Closing Comment

by:Scotto123
ID: 38387903
You anwered my question harrington.  Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question