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
For this, I created a scalar function as follows:
CREATE FUNCTION [dbo].[MaxOrNull](@val1 int, @val2 int) returns int as begin if @val1 >= @val2 RETURN @val1 if @val1 < @val2 RETURN @val2 RETURN NULL end
It's the most elegant solution and can be used anywhere in your SQL code.