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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dates

Status
Not open for further replies.

Laeg

Programmer
Nov 29, 2004
95
0
0
IE
My mind is gone today.

Say I have a table like this

Foo
----------------------------------------------------------------------------------
FooID [int] PK | DateIssued [datetime] | Foo [varchar]| Bar [varchar]

How would I query to say "taking a random date find which
two dates you are between and take the lower datetime value
as the record to return"?
 
Correct me if I'm wrong, but it sounds like that could be re-stated as "find the record with the greatest DateIssued less than or equal to the given date." If so, it's pretty straight-forward. You could just do something like this:
Code:
SELECT * FROM Foo WHERE DateIssued = 
    (SELECT MAX(DateIssued) FROM Foo WHERE DateIssued <= :some_date)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top