Ronald Beuker (8/10/2010)
Oeps, weer wat geleerd. ;-)
The precedence of decimal is higher than that of integer, so the result will be truncated to a decimal(7,6) value of 1.666666.
This is probably a very newbie question, but I am never afraid to ask newbie questions--so here goes: is decimal(7,6) some sort of default?
Long time no see! ;-)
Your question is not a newbie question at all. In fact, this touches on a subject that often leaves seasoned experts looking bewildered at their query results.
What happens is that, as stated in the explanation, data type precedence determines that decimal has a higher precendence then int, so the int argument is converted to decimal. In this case, probably decimal(1,0) but I'm not 100% sure and I can't check. Now both arguments are of the decimal type.
The official explanation of the next step is here: http://msdn.microsoft.com/en-us/library/ms190476.aspx
. The operation used here is division, so the precision (p) of the result is determined as p1 - s1 + s2 + max(6, s1 + p2 + 1), and the scale (s) as max(6, s1 + p2 + 1). Since both operands are decimal (1,0), p1 and p2 are both 1; and s1 and s2 are both 0. If you substitute those numbers in the formulas, you'll see that the results are 7 for precision and 6 for scale.
Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis