473,659 Members | 3,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Previous Date

I'm looking for how to set up a query to return the record with the previous
date to the most recent date. Example:
ReturnDate:
11/15/03
12/12/03
2/4/04
4/5/04

The most recent date is 4/5/04. I need to return the record with 2/4/04.

Thanks!

Mark
Nov 12 '05 #1
6 1752
On Wed, 07 Apr 2004 04:42:48 GMT, "Mark" <mm*****@earthl ink.net>
wrote:

I solved it in two steps, using a similar example from the Northwind
sample application.

1: Create query qryMaxOrderDate :
SELECT Orders.Customer ID, Max(Orders.Orde rDate) AS MaxOfOrderDate
FROM Orders
GROUP BY Orders.Customer ID;

2: Create final query:
SELECT Orders.Customer ID, Max(Orders.Orde rDate) AS SecondToLastDat e
FROM qryMaxOrderDate INNER JOIN Orders ON qryMaxOrderDate .CustomerID =
Orders.Customer ID
WHERE (((Orders.Order Date)<>[MaxOfOrderDate]))
GROUP BY Orders.Customer ID;

-Tom.

I'm looking for how to set up a query to return the record with the previous
date to the most recent date. Example:
ReturnDate:
11/15/03
12/12/03
2/4/04
4/5/04

The most recent date is 4/5/04. I need to return the record with 2/4/04.

Thanks!

Mark


Nov 12 '05 #2
CDB
This is another approach:

SELECT TOP 1 *
FROM [SELECT TOP 2 SomeTable.Retur nDate As RDt
FROM SomeTable
ORDER BY SomeTable.Retur nDate DESC]. As A
ORDER BY A.RDt;

The sub-query notation is for A97/Jet, but also works in A2K/Jet.

Clive
"Tom van Stiphout" <to*****@no.spa m.cox.net> wrote in message
news:el******** *************** *********@4ax.c om...
On Wed, 07 Apr 2004 04:42:48 GMT, "Mark" <mm*****@earthl ink.net>
wrote:

I solved it in two steps, using a similar example from the Northwind
sample application.

1: Create query qryMaxOrderDate :
SELECT Orders.Customer ID, Max(Orders.Orde rDate) AS MaxOfOrderDate
FROM Orders
GROUP BY Orders.Customer ID;

2: Create final query:
SELECT Orders.Customer ID, Max(Orders.Orde rDate) AS SecondToLastDat e
FROM qryMaxOrderDate INNER JOIN Orders ON qryMaxOrderDate .CustomerID =
Orders.Customer ID
WHERE (((Orders.Order Date)<>[MaxOfOrderDate]))
GROUP BY Orders.Customer ID;

-Tom.

I'm looking for how to set up a query to return the record with the previousdate to the most recent date. Example:
ReturnDate:
11/15/03
12/12/03
2/4/04
4/5/04

The most recent date is 4/5/04. I need to return the record with 2/4/04.

Thanks!

Mark

Nov 12 '05 #3
Mark,

From your phrasing I understand you want to set up a query in design view,
not programatically ... which means ve posted to the wrong newsgroup. Anyway,
here it goes:

Make a simple select query on your table. Set the sort order on ReturnDate
to Descending, type the following criterion under ReturnDate:
< DMax("[ReturnDate]","TableNam e")
substituting TableName with the actual table name, and right-click in the
upper half of the design view (source tables area) to open the query
properties. Change the Top Values property from default All to 1.
You should be ready.

HTH,
Nikos

"Mark" <mm*****@earthl ink.net> wrote in message
news:cF******** **********@news read2.news.atl. earthlink.net.. .
I'm looking for how to set up a query to return the record with the previous date to the most recent date. Example:
ReturnDate:
11/15/03
12/12/03
2/4/04
4/5/04

The most recent date is 4/5/04. I need to return the record with 2/4/04.

Thanks!

Mark

Nov 12 '05 #4
"CDB" <al***@delete.w ave.co.nz> wrote in
news:c5******** **@news.wave.co .nz:
This is another approach:

SELECT TOP 1 *
FROM [SELECT TOP 2 SomeTable.Retur nDate As RDt
FROM SomeTable
ORDER BY SomeTable.Retur nDate DESC]. As A
ORDER BY A.RDt;

The sub-query notation is for A97/Jet, but also works in A2K/Jet.


What about an non-equi join, on B.ReturnDate < A.ReturnDate? Then
you can apply criteria easily (even with a paramater), which you
can't do with the "virtual" table approach above.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #5
David,

Could you show what you mean.

Thanks!

Mark
"David W. Fenton" <dX********@bwa y.net.invalid> wrote in message
news:Xn******** *************** ***********@24. 168.128.86...
"CDB" <al***@delete.w ave.co.nz> wrote in
news:c5******** **@news.wave.co .nz:
This is another approach:

SELECT TOP 1 *
FROM [SELECT TOP 2 SomeTable.Retur nDate As RDt
FROM SomeTable
ORDER BY SomeTable.Retur nDate DESC]. As A
ORDER BY A.RDt;

The sub-query notation is for A97/Jet, but also works in A2K/Jet.


What about an non-equi join, on B.ReturnDate < A.ReturnDate? Then
you can apply criteria easily (even with a paramater), which you
can't do with the "virtual" table approach above.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc

Nov 12 '05 #6
"Mark" <mm*****@earthl ink.net> wrote in
news:%W******** *******@newsrea d3.news.atl.ear thlink.net:
"David W. Fenton" <dX********@bwa y.net.invalid> wrote in message
news:Xn******** *************** ***********@24. 168.128.86...
"CDB" <al***@delete.w ave.co.nz> wrote in
news:c5******** **@news.wave.co .nz:
> This is another approach:
>
> SELECT TOP 1 *
> FROM [SELECT TOP 2 SomeTable.Retur nDate As RDt
> FROM SomeTable
> ORDER BY SomeTable.Retur nDate DESC]. As A
> ORDER BY A.RDt;
>
> The sub-query notation is for A97/Jet, but also works in
> A2K/Jet.


What about an non-equi join, on B.ReturnDate < A.ReturnDate? Then
you can apply criteria easily (even with a paramater), which you
can't do with the "virtual" table approach above.


Could you show what you mean.


Well, if you've got a join:

SELECT TOP 1 A.ReturnDate As Date1, B.ReturnDate As Date2
FROM SomeTable AS A INNER JOIN SomeTable AS B On A.ReturnDate <
B.ReturnDate WHERE A.ReturnDate=#1/1/2004#
ORDER BY A.ReturnDate, B.ReturnDate;

Something like that.

The method for doing this is to create the join with the QBE, then
in SQL view, change the "=" to < or > (depending on which you want.
You then won't be able to view the query in the QBE, but it will do
what you want.

The result will be a single row with your the date you filtered for
in the WHERE clause (which could then be parameterized), and the
second column being the next date greater than the date you filtered
on.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1957
by: Mark ??;-\) | last post by:
I would like to display a listing of files on a web page as follows: If there is only one file: display the section name and then display the current file. If there is more than one file (for the first page): display the section name, the current file and a few archive files. If there is more than a page full (for each additional page): display the section name, and the next set of archive files.
1
5178
by: Finlay | last post by:
Hi Group I am designing a report that should show a meter reading for each month and the previous meter reading for the previous month. The months are text stored in a field tMonth. The current month is easy to pull out of the data base but I don't know how to get the previous months meter reading. The previous reading is subtracted from the current reading to get the
1
3885
by: allyn44 | last post by:
Hello, I have a table that has null fields that need to be filled in with the value of the previous record (example below) id date 1 2/2/02 2 3 4/4/02 4
2
1495
by: Amanda | last post by:
This is hotel reservation when a departure date is changed manually by user input ( to a valid date in date format - validity is checkedsomewhere else), the arrival date is set to the previous date upon MouseLeave. How do I calculate the date of the previous day (see mdatArrivalDate = ???? )? (I have already done calculating departure date when an arrrivalDate is modified manually - not via selecting on calendar - to valid data by...
1
1818
by: Jeff | last post by:
I need to place a "Previous Page" link on every page within my site and a simple javascript:history.back() will not work because I need it to capture the state of the page when I left it. For example, if I have a page with some date controls so I can choose a date range and postback the page. It then displays results based on that date range. When I leave the page for another page, I would like to have the Previous Page link take them...
1
4333
by: roveagh1 | last post by:
Hi I've been using the 2 year old link below to repeat values from previous record field into current corresponding field. It's worked fine for text but the last piece of advice was to use the same logic for a date field. i.e. theValue.defaultvalue = "#" & theValue.value & "#" I can't get this to work for some reason and I can't figure out why. Can anyone out there help? Thanks Repeat value of previous record field into current...
6
5177
by: sangith | last post by:
Hi, Is there any module which checks for the previous day's date. For eg I run the program which gives me the current date and I have to check another log file to see if it contains the timestamp as the previous day's date. If it is present, I have to print that particular line to the screen. So please let me know if there is a module available to check for the previous day date. Thanks, Sangith
2
2344
by: favor08 | last post by:
7/19/2007 12:46:30 am. is in a field called CmplteDte. It is a date stamp of when the user completed the item. I need the time for a report but for a form that the supervisors use to QA the previous days work I format the date to 7/19/2007 using a query Format(,"mm/dd/yy") so that they see everything for that date and not just that time. My questions is that when work is stamped after 12 midnight it date stamps to the next day, How do I...
2
4163
by: DThreadgill | last post by:
Not sure how to begin with this one. My table consists of: Branch# (number, double) EntryDate (datetime, mm/dd/yyyy hh:mm:ss am/pm) One branch can have many entry dates (i.e, Branch # 76 has 10 entry dates). I'm trying to show the most recent entry date & the previous entry date on a report. I know how to get the most recent entry date using Max. How would I get to the previous entry date? (Current is 2/14/2008 2:26:07 PM and...
4
11947
by: gimme_this_gimme_that | last post by:
Is there a way to get the last day of the previous business quarter from DB2? For 10/21/2008 the day would be 9/30/2008. Thanks.
0
8337
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,...
1
8531
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,...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
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
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2754
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
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
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.