• Well, I have found the solution. In short:

    [SqlFunction(IsDeterministic = true, Name = "ufn_RunningTotalForDecimal")]

    [return: Microsoft.SqlServer.Server.SqlFacet(Precision = 18, Scale = 2)]

    public static SqlDecimal RunningTotalsDecimal(

    [Microsoft.SqlServer.Server.SqlFacet(Precision = 18, Scale = 2)]

    SqlDecimal val,

    SqlByte id,

    [Microsoft.SqlServer.Server.SqlFacet(Precision = 18, Scale = 2)]

    SqlDecimal nullValue

    )

    {

    string dataName = string.Format("MulstiSqlRt_{0}_{1}", typeof(SqlByte).FullName, id.IsNull ? 0 : id.Value);

    object lastSum = CallContext.GetData(dataName);

    SqlDecimal total = lastSum != null ? (SqlDecimal)lastSum : SqlDecimal.Null;

    if (!val.IsNull)

    total = total.IsNull ? val : total + val;

    else

    total = total.IsNull ? nullValue : (nullValue.IsNull ? total : total + nullValue);

    CallContext.SetData(dataName, total);

    return total;

    }

    }

    That required me to purchase membership on http://www.experts-exchange.com....

    Best,

    Darek