473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Can't get correct data from select query grouping fields

I have a query that is pulling a list of patients seen within a certain time frame at certain locations and it also shows whether they had a certain test done. I want to report by location the list of patients seen and whether the test was done or not.

So in my query I'm grouping by PatientID and PatientName, for my criteria I have a couple of where statements for LocationID and Date. To show if the test was done I have a field Max([test from data].[Value]) AS Result that another field looks at and gives a a value of 0 or 1 so I can sort the report off of IIf([Result] Is Null,0,1) AS TestSort. Last I have the name of the facility as Last(Facilities.Name) AS Facility

Now here's my problem, if a patient was seen at three different locations (say location 10, 11 & 12) but had the test done at location 11 then the result of the query lists location 12 for the facility. If I change the facility name to First(Facilities.Name) AS Facility then I get location 10 in the result.

I can't find the function that applies to the facility so that the result I get comes from the location the test was done at. I've tried the built in functions from the query drop down list on the total row like Max, Min, First, Last but am thinking I need an expression to get what I need.

Can someone help me out?
Jun 12 '08 #1
2 1729
Stewart Ross
2,545 Expert Mod 2GB
Hi dez5000. We'd need to know a bit more about your table design to give a definitive answer - and in particular, how and where do you store the facility code for the facility at which the test was done? First and Last won't help you here, as these functions cannot 'know' what the actual location of the test was. This value has to be stored somewhere for it to be used in your query, and if you could point out where then we can help you with the SQL you need.

To move things along, could you post the metadata for your tables (the relevant fields and their types, along with any related tables), and the actual SQL for your query so far.

I suspect, though, that the problem lies with non-optimal table design and normalisation. I would have expected there to be a facility location field in your table reflecting a normalised relationship between patient test and facility, that could be joined back to your facility table and then grouped within your summary query.

-Stewart
Jun 13 '08 #2
I think I solved my problem. Our medical software uses a MySQL database with tons of tables for the different data it's capturing and since I don't need every table I'm extracting the data I need and in MS Access I created my own single source table to base my query on so that all the data is now stored in a single table called encounters.

Here's a little more information on how I have it working now.

My source table is called Encounters and the table contains an numeric EncounterID field, a date field, numeric PatientID field, numeric FacilityID field, and text fields for patient first and last name (PtFirst & PtLast), a text field for the Location, and a numeric field for the test I'm looking for. I have another query that updates this test field to a 1 if the test was done during that encounter and leaves it blank if it wasn't done.

So my query is:

Expand|Select|Wrap|Line Numbers
  1. SELECT [Encounters].PatientID, [Encounters].PtFirst, [Encounters].PtLast, First([Encounters].Location), Sum([Encounters].[test]) as test
  2. FROM [Encounters]
  3. WHERE (([Encounters].FacilityID) Between 10 And 12) AND (([Encounters].date) Between [Forms]![Input Form]![txtStartDate] And [Forms]![Input Form]![txtEndDate])
  4. GROUP BY [Encounters].PatientID
In my report I have a group header for Location then I sort by test so that the patients without the test done show first and it looks like the patients are being sorted correctly by location using this new source table.
Jun 16 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Shufen | last post by:
Hi, I'm a newbie that just started to learn python, html and etc. I have some questions to ask and hope that someone can help me on. I'm trying to code a python script (with HTML) to get...
1
by: Diego Buendia | last post by:
I'm facing the next problem: I have a table with two columns (among others) modeling category and subcategory data for each row. I need to summarize info on this two columns, but with the next...
5
by: Bayla Frankl | last post by:
Hi all, I am a little stumped. I have a query I am trying to run to retrieve the last Progress Note record from the database for the current patient so that the therapists can see the last note...
0
by: Jason | last post by:
I have a primary form which is used to enter/edit data in a table named Test_Results. On this primary form there is a subform which displays site addresses. This subform is linked to the primary...
9
by: Fish Womper | last post by:
I am at best a part time developer of Access databases. I use Access 2.0, as this is all my employer has on its computers. Even so, to use this ancient version requires a fairly convoluted...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
1
by: lennyw | last post by:
Hi I'm trying to use XSLT to do an xml to xml transformation where the output xml contains summary data on the information in the input xml. I've succesfully done a Muenchian grouping of the...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
3
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.