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

How can I extract most recent dates (three fields)?

Status
Not open for further replies.

irinnew

Technical User
Mar 19, 2005
81
US
Hi everybody
Could you please give me a hand?

I have the following columns in the table :
Date1, Date2, Date 3 (Date2 or 3 can be empty)

In case all three dates or at least 2 of them are populated I need just records with the most recent Date.

How can I do it?

Thank you in advance!

Irin
 
Do you mean you want the most recent date from each *row* in the table?

If thats the case, try something like

SELECT CASE WHEN c3 > c1 AND (c3 > c2 OR c2 IS NULL) THEN c3
WHEN c2 > c1 THEN c2
ELSE c1 END AS most_recent
FROM datestable
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top