?
Solved

Output max datetime instance in multi repsonse query

Posted on 2014-12-29
3
Medium Priority
?
105 Views
Last Modified: 2014-12-29
I have a query to retrieve the last input repsonse to a query.  Below is a sample of the output for two accounts where there are different responses for each account.  I want to only output the last response based on the datetime stamp field.




MaxOfDateTime      VisitID      QueryID      AccountNumber      Response
12/18/2014 2:02:00 PM      A10000418661      CM.LACETOT      A00000260884      3
12/18/2014 3:23:00 PM      A10000418661      CM.LACETOT      A00000260884      4
12/24/2014 7:50:00 AM      A10000419402      CM.LACETOT      A00000261452      1
12/26/2014 1:16:00 PM      A10000419402      CM.LACETOT      A00000261452      2

Here is the SQL for the query above:

SELECT Max(dbo_NurQueryResults.DateTime) AS MaxOfDateTime, dbo_NurQueryResults.VisitID, dbo_NurQueryResults.QueryID, dbo_BarVisits.AccountNumber, dbo_NurQueryResults.Response
FROM dbo_NurQueryResults LEFT JOIN dbo_BarVisits ON dbo_NurQueryResults.VisitID = dbo_BarVisits.VisitID
GROUP BY dbo_NurQueryResults.VisitID, dbo_NurQueryResults.QueryID, dbo_BarVisits.AccountNumber, dbo_NurQueryResults.Response
HAVING (((dbo_NurQueryResults.VisitID) In ("A10000418661","A10000419402")) AND ((dbo_NurQueryResults.QueryID)="CM.LACETOT"))
ORDER BY dbo_BarVisits.AccountNumber;

Open in new window


How do I modify the query to only show the one line for each account?

Thanks

Glen
0
Comment
Question by:GPSPOW
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 40

Expert Comment

by:als315
ID: 40522298
Can you explain field Response? If you remove it, you will be able group other results. If you need this field, you will need nested queries: in first - remove Response and group data, in second - join these results with your query by all four fields
0
 
LVL 8

Accepted Solution

by:
fabriciofonseca earned 2000 total points
ID: 40522339
You will need to create 2 queries.

In the first one you will group by "VisitID" and max "DateTime". Call it query1 for example.

Then you will create a query2 where you use both fields of query1 as key in the join.

If you send your DB it will be easier to send you the full SQL, but you may reach the solution  with the tip above.
0
 

Author Closing Comment

by:GPSPOW
ID: 40522514
Thanks that worked.

Glen
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Suggested Courses

764 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