I want to find the maximum value of multiple columns.
MySQL supports the GREATEST
function but SQL Server doesn't.
Is there any function similar to this in SQL Server 2008?
I want to find the maximum value of multiple columns.
MySQL supports the GREATEST
function but SQL Server doesn't.
Is there any function similar to this in SQL Server 2008?
No. But a sub query can access the columns from the outer query so you can add a sub query
UNION ALL
ing the columns of interest as a derived table then select themax
from that.Or a slightly more concise version as you are on 2008.
I would recommend the following solution:
Try using
TOP
instead orMAX
.For this, I created a scalar function as follows:
It's the most elegant solution and can be used anywhere in your SQL code.
A possible solution:
and the call would be