473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1741
On Wed, 07 Apr 2004 04:42:48 GMT, "Mark" <mm*****@earthlink.net>
wrote:

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

1: Create query qryMaxOrderDate:
SELECT Orders.CustomerID, Max(Orders.OrderDate) AS MaxOfOrderDate
FROM Orders
GROUP BY Orders.CustomerID;

2: Create final query:
SELECT Orders.CustomerID, Max(Orders.OrderDate) AS SecondToLastDate
FROM qryMaxOrderDate INNER JOIN Orders ON qryMaxOrderDate.CustomerID =
Orders.CustomerID
WHERE (((Orders.OrderDate)<>[MaxOfOrderDate]))
GROUP BY Orders.CustomerID;

-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.ReturnDate As RDt
FROM SomeTable
ORDER BY SomeTable.ReturnDate 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.spam.cox.net> wrote in message
news:el********************************@4ax.com...
On Wed, 07 Apr 2004 04:42:48 GMT, "Mark" <mm*****@earthlink.net>
wrote:

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

1: Create query qryMaxOrderDate:
SELECT Orders.CustomerID, Max(Orders.OrderDate) AS MaxOfOrderDate
FROM Orders
GROUP BY Orders.CustomerID;

2: Create final query:
SELECT Orders.CustomerID, Max(Orders.OrderDate) AS SecondToLastDate
FROM qryMaxOrderDate INNER JOIN Orders ON qryMaxOrderDate.CustomerID =
Orders.CustomerID
WHERE (((Orders.OrderDate)<>[MaxOfOrderDate]))
GROUP BY Orders.CustomerID;

-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]","TableName")
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*****@earthlink.net> wrote in message
news:cF******************@newsread2.news.atl.earth link.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.wave.co.nz> wrote in
news:c5**********@news.wave.co.nz:
This is another approach:

SELECT TOP 1 *
FROM [SELECT TOP 2 SomeTable.ReturnDate As RDt
FROM SomeTable
ORDER BY SomeTable.ReturnDate 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********@bway.net.invalid> wrote in message
news:Xn**********************************@24.168.1 28.86...
"CDB" <al***@delete.wave.co.nz> wrote in
news:c5**********@news.wave.co.nz:
This is another approach:

SELECT TOP 1 *
FROM [SELECT TOP 2 SomeTable.ReturnDate As RDt
FROM SomeTable
ORDER BY SomeTable.ReturnDate 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*****@earthlink.net> wrote in
news:%W***************@newsread3.news.atl.earthlin k.net:
"David W. Fenton" <dX********@bway.net.invalid> wrote in message
news:Xn**********************************@24.168.1 28.86...
"CDB" <al***@delete.wave.co.nz> wrote in
news:c5**********@news.wave.co.nz:
> This is another approach:
>
> SELECT TOP 1 *
> FROM [SELECT TOP 2 SomeTable.ReturnDate As RDt
> FROM SomeTable
> ORDER BY SomeTable.ReturnDate 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
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...
1
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...
1
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
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...
1
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...
1
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...
6
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...
2
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...
2
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...
4
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.