Q:

SQL Server Decimal precision

declare @nr1 decimal(20,19),
        @nr2 decimal(20,19)
set @nr1 = EXP(1.0)
set @nr2 = PI();
print @nr1/@nr2

As EXP and PI are "infinite" numbers you should always have enough decimals to print 
The result for this query is 0.865255979432265082
For the query : 
declare @nr12 decimal(34,25),
        @nr22 decimal(34,25)
set @nr12 = EXP(1.0)
set @nr22 = PI();
print @nr12/@nr22

I get the result : 0.865255
So my question is, why is the first query more precise then the second one? As decimal(p,s) as it is define in msdn tells me that the second query should be more precise.

A:

This link will help: http://msdn.microsoft.com/en-us/library/ms190476.aspx
according to this the scale of the result of a division e1/e2 will be given by
this formula max(6, s1 + p2 + 1) and it also includes this note:

The result precision and scale have an absolute maximum of 38. When a result precision is greater than 38, the corresponding scale is reduced to prevent the integral part of a result from being truncated.

probably you will be better using decimal(19,16) given that the scale for exp() and pi() are 16 in both cases.

