Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select MAX date that is less than a specfied date

Status
Not open for further replies.

jgombala

Programmer
Jun 29, 2001
1
US
I am trying to select the MAX date and the revenue amount that corresponds with that date that is less than a date specified.

nID nRevAmt
----------- ----------- ---------------------------
45 0 2001-02-10 00:00:00
45 3628 1999-10-05 00:00:00
45 3810 1999-10-28 00:00:00
45 4335 1999-11-16 00:00:00
45 4603 2000-12-01 00:00:00
45 4755 1999-11-24 00:00:00

If I enter a date of 2000-12-25 I want the following record returned:

nID nRevAmt
----------- ----------- ---------------------------
45 4603 2000-12-01 00:00:00

Thanks
Jeff
 
Select a.nID, a.nRevAmt, a.nDate
From tbl a
Inner Join
(Select nID, Max(nDate) As MaxDate
From tbl Where nDate<'2000-12-25'
Group By nID) As b
On a.nID=b.nID
And a.nDate=b.MaxDate
Terry

&quot;I shall try to correct errors when shown to be errors, and I shall adopt new views so fast as they shall appear to be true views.&quot; - Abraham Lincoln
 
SELECT nID, nRevAmt, nDate FROM my_table
WHERE nDate=(SELECT MAX(nDate) FROM my_table WHERE n_Date<specified_date);

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top