Login     Register

        Contact Us     Search

XLeratorDB/math Documentation

SQL Server function to return the lesser of 2 values


LESSEROF

Updated: 31 March 2013


Use the scalar function LESSEROF to return the lesser of two values passed into the function.
Syntax
SELECT [wctMath].[wct].[LESSEROF](
  <@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 GREATEROF function to return the greater of two values.
·         If @Val1 is NULL or @Val2 is NULL then NULL is returned by the function.
Example
SELECT wct.LESSEROF(9, 143) as LESSEROF
This produces the following result.
LESSEROF
---------
9


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


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


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


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


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


Copyright 2008-2024 Westclintech LLC         Privacy Policy        Terms of Service