?
Solved

Access - query to get next to Last Record which is a group of records.

Posted on 2013-01-18
4
Medium Priority
?
792 Views
Last Modified: 2013-02-02
Hello All
I struggle mightly with this getting the last record and now I need to get the one prior to the last record........
The field I have to select by is the ShiftCashCountID

My current code is
SELECT DISTINCTROW qry_dta_ShiftCashCount_TtlByDenomALL_BusDay.ShiftCashCountID, qry_dta_ShiftCashCount_TtlByDenomALL_BusDay.CurrencyDenominationsID, qry_dta_ShiftCashCount_TtlByDenomALL_BusDay.[Sum Of CountAmt], qry_dta_ShiftCashCount_TtlByDenomALL_BusDay.ShiftID, qry_dta_ShiftCashCount_TtlByDenomALL_BusDay.BusinessDate
FROM qry_dta_ShiftCashCount_TtlByDenomALL_BusDay
GROUP BY qry_dta_ShiftCashCount_TtlByDenomALL_BusDay.ShiftCashCountID, qry_dta_ShiftCashCount_TtlByDenomALL_BusDay.CurrencyDenominationsID, qry_dta_ShiftCashCount_TtlByDenomALL_BusDay.[Sum Of CountAmt], qry_dta_ShiftCashCount_TtlByDenomALL_BusDay.ShiftID, qry_dta_ShiftCashCount_TtlByDenomALL_BusDay.BusinessDate
ORDER BY qry_dta_ShiftCashCount_TtlByDenomALL_BusDay.ShiftCashCountID, qry_dta_ShiftCashCount_TtlByDenomALL_BusDay.CurrencyDenominationsID;

Open in new window

0
Comment
Question by:wlwebb
[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
  • 2
4 Comments
 
LVL 40

Expert Comment

by:als315
ID: 38795955
Do you need only one ShiftCashCountID or it should be found for groups?

Just FYI: You always will get answer quckly if you upload sample DB and show expected result, based on this sample.
0
 
LVL 48

Accepted Solution

by:
Dale Fye earned 2000 total points
ID: 38797401
i'm working from my iPad, so i'm going to make this short

To get the next to last record in a recordset you need to do something like

Select top 1 *
From (
Select top 2 * from yourtable
Order by sortfield DESC
) as temp
Order by sortfield ACS

The sub query sorts your data backwards, so the record you want to get is the 2nd record from that set.

The outer query resorts in your original sort order and takes the top 1 record, which is actually the 2nd to last record in your original result set.
0
 

Author Closing Comment

by:wlwebb
ID: 38847817
Thank you
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38847942
glad I could help.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Suggested Courses

801 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