• ScottPletcher(11/21/2011)

    Interesting code.

    But can't use just do either of these:

    Looks like you and I had the same idea...

    To answer my own question, I found that integer division was a bit of a pain when run through an INSERT/EXEC, even when storing in a DECIMAL field. You have to either format the numbers with decimal points (as you have done), or cast each one in turn.

    Of course, that is an known issue/design-choice with SQL Server's handling of integers, but I imagine a well-functioning expression parser would overcome this by explicitly casting the numbers to a non-integral numeric type.

    The OP's code appears to cast each operand to NUMERIC(18, 6), which would overcome the issue, at least to that precision.