Minimum / maximum function in T-SQL?

I am not asking about common Min / Max functions here. I would like to know if there are functions to get a mix or a maximum of two values, as in:

SELECT Maximum(a,b)
FROM Foo

If the table Foo contains

a b
1 2
4 3

Then the results should be 2, then 4.

I can do this with the IF or CASE statement, but you would think there would be some simple math functions for that.

Thank,

Daniel

+3
source share
1 answer

No. You can write your own UDFs, but UDFs can request slowly . Another option is UNPIVOT data, so you can use the aggregate function. But for small applications, CASE is better.

+4
source

All Articles