Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 12
    Wouldn't it suffice to use WHEN Date1 > Date2 AND Date1 > Date3 THEN Date1; WHEN Date2 > Date3 THEN Date3; ELSE Date3? Commented Jun 30, 2011 at 15:15
  • 25
    The obvious answer, but it doesn't work with NULL values, and attempting to fix that gets very messy. Commented Jan 23, 2012 at 12:49
  • 8
    Necro'ing this older post, but you could wrap each date into a COALESCE to handle NULL's. One of those WHEN statements would then look like: WHEN Date1 >= COALESCE(Date2,'') AND Date1 >= COALESCE(Date3,'') THEN Date3 (do the same for the other when's) Commented Feb 20, 2014 at 17:50
  • 2
    BTW, it returns Date1 when Date2 is null even if Date3>Date1. Commented Sep 20, 2017 at 12:55
  • 2
    Really this answer should be removed since its so bad. Not sure how it got 178 upvotes really, it doesn't work at all if you have NULL values in any of your dates, which is very common. Commented May 27, 2021 at 11:53