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

Compare Dates and find first date => base date

Status
Not open for further replies.

tcgoth

IS-IT--Management
Aug 17, 2005
54
US
I am trying to write an effective query to find the first date that is => than the base date I am comparing it to.

Being relatively new to SQL I do not understand if there is a more direct way of getting to the value rather than having to first find the dates that are => (via subquery?)and then calculate each and every comparison and then use the (MIN) value on the results??

Compare Dates field could be any number of values that must be compared.

For example:

Base Date Compare Dates
1/1/2008 10/1/2007
11/12/2007
12/23/2007
1/3/2008
2/23/2008
3/1/2008

Desired Result:

Base Date 1/1/2008 Compare Dates 1/3/2008

Thanks in advance for any assistance!
 
If these are in 2 different tables, it'd be something along these lines:

Code:
select a.base_date, min(b.compare_date) 
from basedatetable a
left join comparedatetable b
on a.base_date <= b.compare_date
group by a.base_date

HOpe this helps,

Alex

[small]----signature below----[/small]
I'm pushing an elephant up the stairs

My Crummy Web Page
 
What do you have so far?

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
My apologies -this should have been more approrpriately posted in the Crystal Reports section versus here.

I will need to use the logic in a formula field in a Crystal Report.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top