Login     Register

        Contact Us     Search

XLeratorDB/math Documentation

SQL Serve function to return the greater of 2 values


GREATEROF

Updated: 31 March 2013


Use the scalar function GREATEROF to return the greater of two values passed into the function.
Syntax
SELECT [wctMath].[wct].[GREATEROF](
  <@Val1, sql_variant,>
 ,<@Val2, sql_variant,>))
Arguments
@Val1
The first value to be evaluated by the function.
 @Val2
The second value to be evaluated by the function.
Return Types
sql_variant
Remarks
·         If the data types of the expressions are different, @Val2 will be converted to whatever data type @Val1 is for the purpose of the comparison. The datatype of the value returned will remain as it was originally passed to the function.
·         If the comparison is based on a character comparison, one character is considered greater than another if it has a higher character set value.
·         If the comparison is between a number and a date, the date is converted to a float equal to the number of days from 1-Jan-1900 having a fractional component equal to the time component's percentage of a day.
·         Use the LESSEROF function to return the lesser of two values.
·         If @Val1 is NULL or @Val2 is NULL then the other value is returned by the function.
Example
SELECT wct.GREATEROF(9, 143) as GREATEROF
This produces the following result.
GREATEROF
---------
143


SELECT
wct.GREATEROF('9', '143') as GREATEROF
This produces the following result.
GREATEROF
---------
9


SELECT
wct.GREATEROF(CAST('2013-03-27' as datetime), 41358.5) as GREATEROF
This produces the following result.
GREATEROF
---------
41358.5


SELECT
wct.GREATEROF(CAST('2013-03-27' as datetime), cast(41358.5 as datetime)) as GREATEROF
This produces the following result.
GREATEROF
-----------------------
2013-03-27 12:00:00.000


SELECT
wct.GREATEROF(wct.GREATEROF(wct.GREATEROF(9,143),162),799) as GREATEROF
This produces the following result.
GREATEROF
---------
799


SELECT
wct.GREATEROF(103216549870316540031,905168703210654601321) as GREATEROF
This produces the following result.
GREATEROF
---------------------
905168703210654601321
 


Copyright 2008-2024 Westclintech LLC         Privacy Policy        Terms of Service