473,671 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't get correct data from select query grouping fields

4 New Member
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(Facilitie s.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 1743
Stewart Ross
2,545 Recognized Expert Moderator Specialist
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
dez5000
4 New Member
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
6164
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 values from a html form that consists of about 10 checkbox and a textbox where user have to key in a value to perform a search. From python tutors, I learned that I have to use the following method:
1
1668
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 specs: 1.- Some grouping is only on the category column. 2.- Some other grouping consider the two columns. The values for the two columns come from external source, i.e. I have
5
8582
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 while typing the current note. This seemed to be simple to me, since I figured, you take the max(TxDate) that exists before my current date and all should be fine. I tried that and got all the records that exist for this patient before that date.
0
2013
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 form by field named TestID. The subform is used just for displaying site address data, data which is stored in another table named Total_Site_Address. In the Total_Site_Address table there are numerous fields that form the site addresses...
9
2521
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 installation procedure on each PC on which it is used. I am self-taught from the help files that come with Access 2.0 and from painful experience. I've never attended any type of training course on how to develop databases in Access. I have no idea...
6
4868
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 the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
1
1680
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 data from the input xml file, but I can't see how to operate on the grouped result to create and output the desired summary data. If someone could give a reference to an example or provide an actual example I'd really apprecaite it.
52
6314
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 variations(combination of fields), - then act on each group in some way ...eg ProcessRs (oRs as RecordSet)... the following query will get me the distinct groups
3
2835
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 dataset to data in a second dataset, using a common key. I will first describe the problem in words and then I will show my code, which has most of the solution done already. I have built an ASP.NET that queries an Index Server and returns a...
0
8390
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8911
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8597
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8667
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7428
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4402
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2808
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.