QUOTIENT38
Updated 2023-10-13 20:53:12.427000
Syntax
SELECT [wctMath].[wct].[QUOTIENT38](
<@Val1, numeric(38,18),>
,<@Val2, numeric(38,18),>)
Description
Use the scalar function QUOTIENT38 to return the quotient of 2 decimal(38,18) values as a decimal with precision 38 and scale 18. Numeric is functionally equivalent to decimal.
Arguments
@Val1
is the numerator in the division. @Val1 is an expression of type decimal(38,18) or of a type that can be implicitly converted to decimal(38,18).
@Val2
is the denominator in the division. @Val2 is an expression of type decimal(38,18) or of a type that can be implicitly converted to decimal(38,18).
Return Type
numeric(38,18)
Remarks
The maximum value returned by the function is 9999999999999999999.999999999999999999.
The minimum value returned by the function is -9999999999999999999.999999999999999999.
If the quotient of @Val1 / @Val2 is greater than the maximum value or less than the minimum value, a NULL will be returned.
For multiplication, use the PRODUCT38 function.
Examples
This example demonstrates the difference in results between standard decimal multiplication in SQL Server and the QUOTIENT38 function.
CREATE TABLE #q
(
rn int,
val1 decimal(38, 18),
val2 decimal(38, 18)
);
INSERT INTO #q
SELECT *
FROM
(
VALUES
(1, 7619585759.946191323759895577, -7263638718.389916923765520878),
(2, -7236517150.121680095158607665, -8237823811.014787917582286426),
(3, -1072974269.483397474989917713, -3506559607.825265924397605820),
(4, -8910209931.876673030264864492, 7085209667.445452862666748498),
(5, 2003691698.423676141194589012, -5060403565.415278836320768801),
(6, 6474745543.205280874765077983, -3565284889.784689316682404008),
(7, 6166500962.587621712000169636, -7592381528.916681437311194080),
(8, -3012309589.512144867800160787, -1245766000.627675962087184579),
(9, 121713869.001489354804504723, 603392344.184326804682336080),
(10, 5075255044.245070916494217273, -9171756411.873410584811583674)
) n (rn, val1, val2);
SELECT *,
val1 / val2 as [SQL Divide],
wct.QUOTIENT38(Val1, val2) as QUOTIENT38
FROM #q;
DROP TABLE #q;
This produces the following result.
{"columns":[{"field":"rn","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"val1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"val2","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"SQL Divide","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"QUOTIENT38","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"rn":"1","val1":"7619585759.946191323759895577","val2":"-7263638718.389916923765520878","SQL Divide":"-1.049003","QUOTIENT38":"-1.049003957294172093"},{"rn":"2","val1":"-7236517150.121680095158607665","val2":"-8237823811.014787917582286426","SQL Divide":"0.878450","QUOTIENT38":"0.878450099945781621"},{"rn":"3","val1":"-1072974269.483397474989917713","val2":"-3506559607.825265924397605820","SQL Divide":"0.305990","QUOTIENT38":"0.305990597475924744"},{"rn":"4","val1":"-8910209931.876673030264864492","val2":"7085209667.445452862666748498","SQL Divide":"-1.257578","QUOTIENT38":"-1.257578865000507108"},{"rn":"5","val1":"2003691698.423676141194589012","val2":"-5060403565.415278836320768801","SQL Divide":"-0.395954","QUOTIENT38":"-0.395954921879683017"},{"rn":"6","val1":"6474745543.205280874765077983","val2":"-3565284889.784689316682404008","SQL Divide":"-1.816052","QUOTIENT38":"-1.816052782137221141"},{"rn":"7","val1":"6166500962.587621712000169636","val2":"-7592381528.916681437311194080","SQL Divide":"-0.812195","QUOTIENT38":"-0.812195875444564043"},{"rn":"8","val1":"-3012309589.512144867800160787","val2":"-1245766000.627675962087184579","SQL Divide":"2.418038","QUOTIENT38":"2.418038048874668685"},{"rn":"9","val1":"121713869.001489354804504723","val2":"603392344.184326804682336080","SQL Divide":"0.201715","QUOTIENT38":"0.201715965034365261"},{"rn":"10","val1":"5075255044.245070916494217273","val2":"-9171756411.873410584811583674","SQL Divide":"-0.553356","QUOTIENT38":"-0.553356938009696462"}]}