According to the documentation / (Division) (Transact-SQL) the result type is related to the Data Type Precedence, that said, in the following scenario, is there any way to receive the result type as a decimal(38, 10) ?
The calculation result seems loosing precision... A precise result should be 0.8123567224
declare @a decimal(38,10) = 0.8123567216;
declare @b decimal(38,10) = 0.9999999990;
select
[a] = @a
,[b] = @b
, result1 = @a / @b
, result2 = @a / CONVERT(decimal(38, 10), @b)
, result3 = CONVERT(decimal(38, 10), @a) / CONVERT(decimal(38, 10), @b)
, result4 = CONVERT(decimal(38, 10), (CONVERT(decimal(38, 10), @a) / CONVERT(decimal(38, 10), @b)))
The rules for the resultant precision and scale for decimal division are noted in the table on this documentation page. This is the relevant table entry:
The doc excerpt:
This can be observed with
sys.dm_exec_describe_first_result_set:If we reduce the integral part of the
result3operands fromdecimal(38, 10)todecimal(28, 10), the result type is the more precisedecimal(38, 10), sufficient for the 0.8123567224 value: