Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / November 2005

Tip: Looking for answers? Try searching our database.

Using dates in criteria

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim - 17 Nov 2005 17:13 GMT
I am putting citeria in a query for a table. The table has values associated
with dates that are both less than and greater than today.  I would like to
set a criteria that says, "If there is a date that is greater than today then
return the value for that date as well as a value for only the last date
before today.  If there is no date greater than today then return the value
for only the last date befoe today."
Example table
Item            Date           Value
123             10/1/2005     40
123             12/1/2005     20
345             9/1/2005       30
345             8/1/2005       25

In the above table Item 123 has a future value and a past value so I would
like to see both.  Item 345 has no future value but multiple past values.  I
only want to see the most recent past value.

Thoughts?  Thanks for your help.
John Spencer - 17 Nov 2005 17:38 GMT
One method might be

SELECT ITEM, Example.[Date], [Value]
FROM Example
WHERE Example.[Date] > Date()
OR [Date] IN
  (SELECT Top 1 Tmp.[Date]
   FROM Example as Tmp
   WHERE Tmp.Item = Example.Item
   And Tmp.Item <Date()
   ORDER BY Tmp.Date DESC)

>I am putting citeria in a query for a table. The table has values
>associated
[quoted text clipped - 19 lines]
>
> Thoughts?  Thanks for your help.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.