• Cool, glad it worked well for you. Another optimization you might try is using the t-sql "returns null on null input" option, which allows sql server to short-circuit null handling without needing to even start running your clr code (you could then get rid of the explicit .IsNull checks in the clr code).

    The diff between decimal and double is that double is a binary approximation of your values (based on ieee 854 std I believe), so you lose some scale accuracy. Decimal is an exact representation of your decimal values, related to the old binary coded decimal system. The important thing is that all the Math lib functions you're using deal in double data type, and those implicit conversions cost you. For a spatial data app I'd expect double to be "close enough" in most cases. If you need more accuracy than the double data type provides you'll probably need to use a different math library.

    Mike C