Queries :: Most Recent Data Across Two Fields

Aug 23, 2014

I have a table called tbl Meeting Response. It records the data about churches where I have scheduled a representative. Two of the fields in the tbl Meeting Response are 1. Normal Attendance (how many the church normally runs) and 2. Tour Year (the year we were there). Reps have been scheduled at many of these churches more than once over the years, so there are records for different years for the same church in the Meeting Response table.

I want to create a query that will show a field with the most recent normal attendance from the Meeting Response table. This would require comparing the information between two different fields -- Normal Attendance and Tour Year. 1. If a rep was at that church in 2014, 2013 and 2012, and we have a Normal Attendance number for all 3 years, I want the field to show the attendance submitted in 2014 (the most recent). However, if the rep didn't call in a normal attendance in 2014, and the most recent attendance we have is 2012 (i.e., the Normal Attendance is blank for both 2014 and 2013), then I want that field to show the attendance for 2012 (the most recent).

View Replies


ADVERTISEMENT

Queries :: Get Most Recent Record Based On 3 Different Fields

Jun 2, 2014

I have a table similar to the following:

PatientID | LabID | LabDate | Result
001 | 55 | 01jan14 | 9.5
001 | 55 | 01feb14 | 10.0
001 | 55 | 01mar14 | 8.7
001 | 66 | 30jan14 | 11.2
001 | 66 | 30feb14 | 15.4
001 | 66 | 30mar14 | 13.0

002 | 55 | 01jan14 | 12.1
002 | 55 | 01feb14 | 9.9
002 | 55 | 01mar14 | 14.5
002 | 66 | 30jan14 | 16.5
002 | 66 | 30feb14 | 13.0
002 | 66 | 30mar14 | 10.0

Using a single-step Access query, I need to retrieve, for each PatientID, the most recent LabDate and Result *of a given LabID*. Thus, from the example dataset above, the desired output for LabID 55 is:

PatientID | LabID | LabDate | Result
001 | 55 | 01mar14 | 8.7
002 | 55 | 01mar14 | 14.5

I have searched this forum and others, but have not found an answer that I can directly tanslate to my situation. I have successfully written queries (with included subqueries) that retrieve the most recent of all the Labs, but have failed at obtaining a result dataset that contains only the records within a specified LabID.

For example, the query below fails because whenever the most recent of *all* the LabDates is not the same as the most recent of *the LabDates with a LabID=55*, the correct record is not included in the results. In the example dataset above, 0 records are returned.

SELECT a.PatientID, a.LabID, a.LabDate, a.Result
FROM Labs AS a
INNER JOIN (SELECT PatientID, MAX(LabDate) AS MaxLabDate FROM Labs GROUP BY PatientID) AS b
ON (a.PatientID = b.PatientID) AND (a.LabDate = b.MaxLabDate)
WHERE (((a.LabID)=55));

View 3 Replies View Related

Queries :: Most Recent Data From A Date

Jul 30, 2014

I have a problem here that I've been wrestling with for a while.I have a table, ID, Date, and Grade.It is set up that way, and I tried

Code:
SELECT tblGrades.StudentID, tblGrade.Grade, Max(tblGrade.GradeDay)
FROM tblGrades
GROUP BY tbGrades.StudentID, tblGrades.Grade;

I figured since I'm grouping by both StudentID and Grade, it wont return the most recent grade from that Student. Is there any way for me to NOT group by Grade and just display the results of the Max(GradeDay?)

View 1 Replies View Related

Queries :: Find The Recent Available Data Based On Dates?

Jul 9, 2014

I have a price table:

Code:
tblPrice
PosNr PriceDate Company Price
1 01.01.2014 Firma A 5
2 02.01.2014 Firma A 7
3 03.01.2014 Firma A 9
4 04.01.2014 Firma A 8
5 06.01.2014 Firma A 6
6 02.01.2014 Firma XY 11
7 03.01.2014 Firma XY 9
8 04.01.2014 Firma XY 7
9 05.01.2014 Firma XY 8
10 06.01.2014 Firma XY 10

And I have a table with the dates, for which I need a price.

Code:
tblDates
PosNr PriceDate Company
1 01.01.2014 Firma A
2 02.01.2014 Firma A
3 03.01.2014 Firma A
4 04.01.2014 Firma A
5 05.01.2014 Firma A (no price available)
6 06.01.2014 Firma A
7 02.01.2014 Firma XY
8 03.01.2014 Firma XY
9 04.01.2014 Firma XY
10 05.01.2014 Firma XY
11 06.01.2014 Firma XY

And now I want to combine this tables, and for the dates which have no price, the last price should be taken.

Code:
tblResult
PosNr PriceDate Company Price
1 01.01.2014 Firma A 5
2 02.01.2014 Firma A 7
3 03.01.2014 Firma A 9
4 04.01.2014 Firma A 8
5 05.01.2014 Firma A 8 (actualy no priceavailable, so take last price)
6 06.01.2014 Firma A 6
7 02.01.2014 Firma XY 11
8 03.01.2014 Firma XY 9
9 04.01.2014 Firma XY 7
10 05.01.2014 Firma XY 8
11 06.01.2014 Firma XY 10

how I can get this?

I have this code, but it need hours.

Code:
SELECT tblDates.PosNr, tblDates.Company, tblDates.PriceDate, (SELECT TOP 1
B.Price
FROM
tblPrices As B
WHERE
B.Company = tblDates.Company
AND
B.PriceDate <= tblDates.PriceDate
ORDER BY
B.PriceDates DESC ) AS Price
FROM tblPrices RIGHT JOIN tblDates ON (tblPrices.PriceDate = tblDates.PriceDates) AND (tblPrices.Company = tblDates.Company);

View 14 Replies View Related

Query: Most Recent Date From Several Fields In Two Tables

Jul 15, 2005

I have a parent table [Case] and a child table [Action], in a one-to-many [Access 2003].

The parent has an open date and a closed date.

The child has a received date and a completed date.
The child may contain more than 1 record that matches the parent.

Date fields for activities that have not yet happened are blank.

A typical example might be one parent and two child entries for a total of six dates fields.

I am after only a [single] most-recent action date of the six [there could be a tie for that most recent date, and then there would be two records returned in the result].

I am working for a table that includes a list of every parent record with the name and date of the most recent, or latest activity date.

After two days I decided to ask for help.

Thanks,

View 1 Replies View Related

Query That Grabs Most Recent Date, And Associated Fields

Dec 10, 2007

The database I am working with contains several different tables and a variety of information. I need to create a query that accesses information from two different tables. Though the tables contain other fields, the fields I am most interested in are:

Table 1: Protocol Information
"Protocol ID", "Title", "Expiration Date"

Table 2: Regulatory Submission
"Protocol ID", "Description of Submission", "Submitted By", "Date of Submission".

The way the data is stored, each protocol has a Protocol ID, and there is only one record per protocol in the "Protocol Information" table.

However, each time these protocols are submitted to our review board, a log is created in the "Regulatory Submissions" table.

I need to generate a query that pulls only the most recent submission date, so that the query output would look like this:

"Protocol ID", "Title", "Description of Submission", "Submitted By", "Date of Submission" (Where this is the most recent one), "Expiration Date"

From other forums and posts, I tried to create an SQL aggregate function, using Max or Last to get the most recent date. I was successful, but only if the query contained just the "Protocol ID", "Date Submitted", and "Description of Submission" fields. Adding any more, or creating a query to use the outputted data didn't work (it could be that my second query was not written correctly.) I am very novice at creating complex queries, and at SQL.

One additional complication: There are two values in the "Description of Submission" field of the "Regulatory Submissions" table that I am not interested in. They are "Adverse event" and "AE Summary Log". I can successfully filter them out using a criteria expression, but integrating all of these pieces has not been easy (or possible, yet).

I'm out of ideas. This is really complicated, and I apologize. Any assistance would be greatly appreciated.

View 14 Replies View Related

Find Most Recent Invoice And Most Recent Funding For Client

Feb 19, 2008

Hello all

I'm sure the answer is on here somewhere but trying to find it and then getting it to work is a bit of a problem, so i resorted to posting.

I have 5 tables
Partnership Details, Invoices, Funding, Communication, Communication Types.

the field Partnership Name in the Partnership Details table has a one to many relationship with the partnership name on tables: Invoices, Funding and Comunication.

What I want to do is create a query that will show the most recent invoice (detirmined by date) and the most recent funding (detirmined by date) for each partnership.

I can do this using max if I only want the feilds Partnership name, invoice date and funding date. however I want to create a report that will show several feilds from partnership details and I want to show the invoice no. and amount as well as the date and also the amount and notes field for funding

Is anyone able to help?

Thanks
Niyx

View 3 Replies View Related

Queries :: Show Only Most Recent Date For Each Customer

Nov 4, 2014

I have a query that selects a group of customers and order dates.

I want the query to only show the most recent date for each customer.

How would i achieve this?

View 2 Replies View Related

Queries :: Select Query - Most Recent Date

Dec 24, 2013

How would you write a Select Query to select the most recent dates?

Select OrderDates
From Orders
Where >=Date()

No good if recent date is older than todays date!

View 3 Replies View Related

Queries :: JOIN Query To Return Most Recent Record?

Aug 18, 2014

I have two tables with a one to many relationship. The tables are linked by the INDEX column.

EXAMPLE:

Code:
TABLE_1
INDEX NAME
1 Name_A
2 Name_B
3 Name_C

TABLE 2
INDEX NUM_INDEX STATUS
1 1 REJECTED
1 2 REJECTED
1 3 OPEN
2 1 CLOSED
3 1 REJECTED
3 2 OPEN

I need the NAME field from TABLE_1 and the Last STATUS field from TABLE_2 (MAX of NUM_INDEX).

Example:
Name_A, OPEN
Name_B, CLOSED
Name_C, OPEN

SQL that I have now.

Code:
SELECT A.FIN_Finding_Number, B.Max_Index
FROM TBL_Findings AS A INNER JOIN (SELECT RES_Finding_Index, Max(RES_Response_Index) As Max_Index
FROM TBL_Response GROUP BY RES_Finding_Index ) AS B ON A.FIN_Finding_Index = B.RES_Finding_Index
WHERE (((A.FIN_Finding_Index)=34));

This SQL statement will return me the Finding_Number and Max_Index. I don't need the Max_Index. I need the Status. If I put the Status in the Sub-Query and GROUP BY it, it will return both REJECTED and OPEN. I just need it to return OPEN.

View 2 Replies View Related

Queries :: How To Get A List Of ALL Equipment Showing Most Recent Date And Time

Mar 23, 2013

I've got three tables:

Code:
tblequipment
equipmentid
equipmentnumber (user defined ID)

tblrentals
rentalid
rentaldate
rentaltime
fromparty (c for customer, e for employee, o for other)
frompartyid (foriegn key to either customer, employee or other)
toparty (same as from)
topartyid (same as from)

tblrentaldetails
detailid
rentalid
equipmentid

How can I get a list of ALL equipment showing the most recent date and time, also showing the respective toparty and topartyid? I can get it fairly easily, except for including toparty and topartyid.

View 2 Replies View Related

Queries :: Average Price Of Last 5 Line By Items By Recent Date

Mar 4, 2015

Any way to filter the average price of of a Product within the last 5 occurences (Line Items). It would pull a week back so WHERE: Between Now()-7 and Now(). Example:

Code:
PARTID | Price | Date
--------------+-------------+---------
111223344 | 5 | 3/1/2015
111223344 | 7 | 3/2/2015
111223344 | 8 | 3/4/2015
111223344 | 10 | 11/22/2014
111223344 | 20 | 10/1/2014
111223355 | 5 | 2/5/2015
111223355 | 6 | 2/1/2015

to:

What I want:

Code:
PARTID | avgPrice | MinDate
--------------+----------------+-------------
111223344 | 10 | 10/1/2014
111223355 | 5.5 | 2/1/2015

View 4 Replies View Related

Queries :: Subquery To Return Latest / Most Recent Value For Each Record In Main Query

May 7, 2014

I have a table of accounts and a table of rates. There is a one-to-many relationship between them (i.e. each account can have multiple rates, each with their own - unique - effective date)

I'm trying to build a query which will show me all of the accounts in the accounts table and the most recent rate (based on the effective date) for each of those accounts.

This is as far as I've gotten with the SQL :

Code:
SELECT [tblAccounts].[AccountID], [tblAccounts].[AccountNumber], [tblAccounts].[AccountName], [LatestRate].[IntRate], [LatestRate].[EffectiveDate]
FROM [tblAccounts]
LEFT JOIN
(SELECT TOP 1 [tblRates].[AccountID], [tblRates].[IntRate], [tblRates].[EffectiveDate]
FROM [tblRates]
ORDER BY [tblRates].[EffectiveDate] DESC) AS LatestRate
ON [tblAccounts].[AccountID] = [LatestRate].[AccountID]

But this can't work because the [LatestRate] subquery can only ever return one record (i.e. the most recent rate across all of the accounts)

I need the most recent rate for each of the accounts in the main query

(FYI - I use an outer join as it is possible for no rate to be available in the rates table for a given account, in which case I want to return the null value rather than omit the account from the resulting dataset...)

View 2 Replies View Related

Queries :: Products Form - Listbox To Show Recent Inventory Transactions

Apr 3, 2014

I have a products form, we are a manufacturing company, with a listbox to show recent inventory transactions. This is based on a query which shows all transactions with the current part id, and that all works well and fine.

The problem is, I would like to limit this query to show only the last 10 transactions in the listbox and not make it editable, ie not enabled. I set the show only in query design view to 10 and it says in the sql statement select top 10, however, the listbox consistently shows all related records. What am I missing?

View 8 Replies View Related

Queries :: Appointment Database - Query Most Recent Entry For Each Record In Separate Table

Jun 20, 2013

I have a database that is used to allocate appointments to our staff. It has 2 tables, one that lists the clients we need to call in that day, and another that stores details of each contact attempt. I'd like to design a query that find all clients who we have not dealt with so we can easily get their details in a list. I know what the criteria for the query would be, but I'm stuck for how to actually execute it. Here are the details.

Table tClients stores the current clients - primary key is named "clientRef"
Table tContactEvents stores each contact attempt and the date/time is stored in a field named "dateTime".

When an entry has been dealt with successfully a yes/no field named "completed" will be set to "Yes".

There may be many attempts to contact a specific client on a given day, unsuccessful attempts will not have the completed flag set.

Once the completed flag is set that client will be ignored so no further entries will appear.

So I need a query that searches tContactEvents for the most recent match to each number in tClients.clientRef and checks if the completed flag is set. If the completed flag is false, or if the number has no match (i.e. no contact attempts made yet) then the clientRef should be displayed. I also need this to be restricted to the current date, as the same client could have rebooked their appointment to a different day.

View 10 Replies View Related

Queries :: Duplicate Data From Two Different Fields

Jul 2, 2014

Any way to query duplicate data from two different fields from two different tables in the same access 2010 project. I first quried the first part since it combines the first 3 columns to create another value (i.e. 52 & 60 = 5260).

So I created the concatenative value but now I have to compare to another field to display what results are found in both the concatenative and the other (APN in the file). I tried using query wizard but it is for only one field. I understand you have to use joins but the destination filed is what gets me.

View 4 Replies View Related

Queries :: Turning 2 Fields Of Data Into 1

Jun 17, 2014

I have a table in a database where the telephone numbers are in two separate fields, i.e. [123] (which is the areacode) and [456-7899]. Is there a way to take the two fields in this table and put combine these two numbers into one field so the new field will be in this format.... [123-456-7899]?

View 9 Replies View Related

Queries :: Linking Data On 2 Fields

Sep 5, 2014

I then have various support queries that group customers based on reason for visit, type of visit etc. I need to be able to link this to my main table so that each customer has a category against them. The issue I have is that some customers will have more than one visit ref, which can also mean they have multiple reason for visits. I need to make sure that when I link my queries back to the main table that the right category appears against the customer and their correct visit ref.

View 1 Replies View Related

Queries :: Pull Data From Fields In 2 Different Tables

May 6, 2013

I have a query that pulls data from the following fields in 2 different tables:

Area1FloorPrep (tblFloorPrep) ex. remove ceramic tile
Area1Size (tblInstallationAreas) ex. 20 s/f, or just 20
Area2FloorPrep (tblFloorPrep)
Area2Size (tblInstallationAreas)....

All the way to Area20 (Floorprep and InstallationAreas) for both tables. I have created an installer invoicing form that pulls the data from the workorder that these fields are located in, but the problem I'm having is that I don't know what kind of query to create to concatenate the data in the 20 fields and concatenate the size of the areas next to the appropriate concatenated floor prep description. Is there a way to do this without coding?

View 3 Replies View Related

Queries :: Update Some Data From Another Table - Joining Fields?

May 8, 2013

All; using 2010. I have a table that I need to update some data from another table. I want to use the SSN but one of the SSN fields in the table has letters at the end of it and doesnt return any records. How can I join fields?

View 1 Replies View Related

Queries :: Compare Data In 3 Fields In 1 Table / Group By Largest

Dec 4, 2013

I'm trying to create a query that will compare the data in 3 fields in a record, choose the largest (I also have a criteria to order by if more than 1 field has the same entry and it's the largest of the 3), and then group by that.The fields I will need are as follows:

PRODUCT table:
ProductName
Chemical
ChemicalAbstract
PhysicalState
NFPAHealth
NFPAFlammability
NFPAReactivity

qryQuantityOnHand query (which doesn't link directly to the PRODUCT table, it links through associations with other tables):QOH...I will eventually need information from another table for the final reports, but I don't think it has to be included in this query.

The fields NFPAHealth, NFPAFlammability, and NFPAReactivity each may be 0, 1, 2, 3, or 4...I need to ignore blanks; if 1 of the above fields is blank, they will all be blank.For any record, I need to compare the number in those 3 fields to each other, and choose the largest number and group by that rating.

In other words, if the largest of the 3 numbers is a 3 in the NFPAFlammability field, all those products need to be grouped together.If the same number appears in at least 2 of the fields, the order that determines the grouping is: Flammability, then Health, then Reactivity..Ultimately the report will be grouped as follows:

Flammability
Rating 4
Product 1
Product 2
Product 3

Rating 3
Product 1
Product 2
Product 3

Rating 2
Product 1
Product 2
Product 3

Health
Rating 4
Product 1
Product 2
Product 3

[code]....

and each of the groups will be sub-totalled.I'm stumped at trying to create the query in the first place.The added aggravation here is that we are dealing with 23 stores, each with their own mix of products. I have another table that contains the information about which products are in which store.

View 4 Replies View Related

Queries :: Excluding Records From Search Results That Have Fields With No Data?

Aug 6, 2015

I have a search form with 12 fields. In my query I use

Code:

Like "*" & [Forms]![CustomerRetestDatabaseSearch]![RetestLocation] & "*" Or Is Null

for each field on the search form.

I get the results I expect, it finds all records that match the criteria. Even if some of the fields in a record are null.

But if the query finds a record that matches one field I enter criteria into, and nulls for the other fields I enter criteria into it displays the record. I want to show exact matches. (If what I entered is null... don't show the record).

The reason I have "Or Is Null" is to include the records for the fields I left blank on the form.

Search Form with Criteria.PNG

Search Query.jpg

Search Results With Missing Entered Criteria(Dont Want These Records Included).jpg

View 2 Replies View Related

Queries :: Pull Data From Fields That Have Values With Decimal Places

May 9, 2013

I have a query that pull data from hours worked fields that have values with decimal places. Hours is multiplied to rates to create my amount to charge in my query which is then displayed on my invoice report.

The issue is that when I sum my amount, my subtotal is off by $.01 due to the decimals entered for the hours worked (e.g. hours worked is 1.5*32.75=49.125)

I need the rounding to work in the query and display on my report as $49.13 and the subtotal to reflect it. I have the properties in my table as double with decimal place at 2, and my query and report properties with decimal place at 2 as well. It still isn't working.

View 2 Replies View Related

Queries :: Enabling / Disabling Fields According To Previous Data Entry

Aug 6, 2013

I need to create a form to enter data from a survey, and ideally some sections of the form would only be completed when the answer to a first question is "yes". How to do this enabling/disabling of fields for data entry?

View 3 Replies View Related

Queries :: Not Criteria To Bring Up Records - Multiple Fields With Data

May 30, 2015

I'm creating a query from one table using two fields that require certain records to NOT bring up records that have the following text:

One table, two fields

First field ECO LifeCycle Status Criteria is Not "ERP UPDATE" or "CANCELLED"
Second field ECR LifeCycle Status Criteria is Not "COMPLETE"

When I put the Not Criteria in the first field only I get a result.
When I put the Not Criteria in both fields I get no results.

View 9 Replies View Related

Queries :: Access Brings Back No Data If Fields Are Blank

Jul 5, 2013

I have a query that I made for about five fields, where the criteria is

Like "*" & [Forms]![DATA SEARCH]![Box] & "*"

Where box is the name of the field that I am searching for.

However, some of the fields in my form are left blank, which makes this refuse to give any results when I try to query it with a form. The other problem that I have is that the fields are bland in different parts of the 1,000 some-odd row table, which was imported from MS Excel.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved