Connecting Tech Pros Worldwide Forums | Help | Site Map

Showing last 3 dates

Newbie
 
Join Date: Jun 2009
Posts: 12
#1: Oct 22 '09
Hi,

I'm working on a query using MS Access 2003. Right now on my query it showed all receipt dates for items from the beginning up to now. On the report, I just want to show the last 3 receipt dates. How can I do this? Could someone help? I know for the last date I can just use max, but what about the last 2?

Thank you in advance.

NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#2: Oct 22 '09

re: Showing last 3 dates


What you need to do is sort the results in your query (by date descending) then set (Properties of the QueryDef) Top Values to 3.
Newbie
 
Join Date: Jun 2009
Posts: 12
#3: Oct 22 '09

re: Showing last 3 dates


Thank you Neopa for your quick response.

But now the result only showed my top 3 value on the query. But my query have all items that we receipt from beginning FY up to now. I need for all that items to show on the report, but for the date, I just need the last 3 receipts date for each items. If there's an item only have 2 dates, then the 3rd date will be blank. Can you help me please? I'm sorry for not givinng you a clear picture earlier.
here is my query
Expand|Select|Wrap|Line Numbers
  1. SELECT FY09_LastReceiptDate_1.ID, FY09_LastReceiptDate_1.TRANSACTION_DATE AS LastReceiptDate
  2. FROM FY09_LastReceiptDate_1
  3. GROUP BY FY09_LastReceiptDate_1.ID, FY09_LastReceiptDate_1.TRANSACTION_DATE
  4. ORDER BY FY09_LastReceiptDate_1.ID, FY09_LastReceiptDate_1.TRANSACTION_DATE DESC;
  5.  
Thank you.
Newbie
 
Join Date: Jun 2009
Posts: 12
#4: Oct 22 '09

re: Showing last 3 dates


Nevermind I found the answer. Basically I just need to create a function that showed 1, 2, 3 as a new field. then from that I just create another query that showed data with number < 4

Thank you for all your help.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#5: Oct 23 '09

re: Showing last 3 dates


I think this can be done in pure SQL Bay (so in a QueryDef). Unfortunately I'm still not clear exactly what you're after here, so I knocked up something I hope will illustrate the concept :
Expand|Select|Wrap|Line Numbers
  1. SELECT   tTBG.GroupField,
  2.          tTBG.SortField
  3.  
  4. FROM     tblTopByGroup AS tTBG 
  5.  
  6. WHERE    tTBG.ID In(
  7.     SELECT TOP 3 inTBG.ID
  8.  
  9.     FROM         tblTopByGroup AS inTBG
  10.  
  11.     WHERE        (inTBG.GroupField=tTBG.GroupField)
  12.  
  13.     ORDER BY     inTBG.SortField
  14.     )
  15.  
  16. ORDER BY tTBG.GroupField,
  17.          tTBG.SortField
Reply