This feels like it should be an easy one. How do I get the latest of 3 dates that are in different columns
DROP TABLE #dates
CREATE TABLE #dates (mykey CHAR(10), date1 DATETIME, date2 DATETIME, date3 DATETIME)
INSERT #dates VALUES ('Key1', '1/1/2015', '2/1/2015', '3/1/2105')
INSERT #dates VALUES ('Key2', '1/2/2015', '4/2/2015', '3/2/2105')
INSERT #dates VALUES ('Key3', '1/3/2016', '4/3/2015', '3/3/2105')
select mykey, ?? AS 'Latest Date' from #dates
I would like the result to be:
mykey Latest Date
Key1 2105-03-01 00:00:00.000
Key2 2015-04-02 00:00:00.000
Key3 2016-01-03 00:00:00.000