Groups | Blog | Home
all groups > sql server (alternate) > september 2004 >

sql server (alternate) : Function that returns highest of two columns?


philipdm NO[at]SPAM msn.com
9/21/2004 8:41:16 AM
Is there a function that compares two columns in a row and will return
the highest of the two values? Something like:

Acct Total_Dollars Collected Total_Dollars_Due
11233 900.00 1000.00

Declare @Value as money
set @Value=GetHighest(Total_Dollars_Collected,TotalDollars_Due)
Print @Value


This function will return 1000.00 or the Total_dollars_Due??

jcelko212 NO[at]SPAM earthlink.net
9/21/2004 2:58:53 PM
[quoted text, click to view]
return the highest of the two values? <<

in Oracle, there is a general GREATEST(<list>) function, but in
Hugo Kornelis
9/21/2004 6:12:51 PM
[quoted text, click to view]

Hi Philip,

No. But you can create a user-defined function, if you wish. Or simply use
a CASE expression:

SET @Value = CASE WHEN a > b THEN a ELSE b END

The user-defined function might be more friendly to the eyes. Using the
CASE expression wherever you need it might be a little bit less readable,
but it will probably perform better.

Best, Hugo
--

AddThis Social Bookmark Button