date formulas

G

Guest

I need to be able to search a table for any records that are equal to a given
date field and if no records have that date exactly to have it present the
next existing prior date. I tried doing iif(table date<=given date, table
date, null) and then having this be a total query with MAX on this column but
it doesn't do what I'm looking for. How is this criteria or expression
written?
 
G

Guest

I would combine <= in the criteria with TOP 1
SELECT TOP 1 *
FROM tblNoNameGiven
WHERE [Table Date]<=[Given Date]
ORDER BY [Table Date] DESC;
 
T

Tom Ellison

Dear skigal:

I would think what you probably could use would be a subquery returning the
MAX(somedate) WHERE somedate <= given date.

SELECT *
FROM sometable
WHERE somedate = (SELECT MAX(somedate)
FROM sometable
WHERE somedate <= [Enter Date: ])

Perhaps you can flesh this out with the names of your table and date column.

Tom Ellison
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top