SQL MAX of multiple columns?
SQL MAX of multiple columns?
SQL MAX of multiple columns?
Re: SQL MAX of multiple columns?
This is an old answer and broken in many way.
See [https://stackoverflow.com/a/6871572/194653](https://stackoverflow.com/a/6871572/194653) which has way more upvotes and works with SQL Server 2008+ and handles nulls, etc.
**Original but problematic answer**:
Well, you can use the CASE expression:
```
SELECT
CASE
WHEN Date1 >= Date2 AND Date1 >= Date3 THEN Date1
WHEN Date2 >= Date1 AND Date2 >= Date3 THEN Date2
WHEN Date3 >= Date1 AND Date3 >= Date2 THEN Date3
ELSE Date1
END AS MostRecentDate
```
See [https://stackoverflow.com/a/6871572/194653](https://stackoverflow.com/a/6871572/194653) which has way more upvotes and works with SQL Server 2008+ and handles nulls, etc.
**Original but problematic answer**:
Well, you can use the CASE expression:
```
SELECT
CASE
WHEN Date1 >= Date2 AND Date1 >= Date3 THEN Date1
WHEN Date2 >= Date1 AND Date2 >= Date3 THEN Date2
WHEN Date3 >= Date1 AND Date3 >= Date2 THEN Date3
ELSE Date1
END AS MostRecentDate
```