Daniel Williams
Daniel Williams

Reputation: 9304

Minimum/Maximum function in T-SQL?

I am not asking about the aggregate Min/Max functions here. I would like to know if there are functions to get the mix or max of two values as in:

SELECT Maximum(a,b)
FROM Foo

If table Foo contains

a b
1 2
4 3

Then the results should be 2, then 4.

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

Thank you,

Daniel

Upvotes: 3

Views: 759

Answers (1)

jimconstable
jimconstable

Reputation: 2388

There is not. You can write your own UDFs but UDFs can slow queries down. Another option is to UNPIVOT the data so you can use the aggregate function. But for small applications CASE is best.

Upvotes: 4

Related Questions