• Sergiy (8/29/2016)


    Jeff Moden (8/29/2016)


    Someone would have to prove that one to me, Sergiy.

    It took 2 minutes:

    DECLARE @Amount MONEY, @Term INT

    DECLARE @fRate float, @dRate decimal (38,10)

    SELECT @Amount = 1000000, @Term = 17*9*13*7

    SELECT @fRate = CONVERT(FLOAT, @Amount)/@Term,

    @dRate = CONVERT(DECIMAL(38,10), @Amount)/@Term

    SELECT @fRate, @fRate * @Term fAmount,

    @dRate, @dRate * @Term dAmount

    Took just a glance to realize that you crippled the decimal scale to be less than that of the FLOAT return and only slightly more to fix it. 😉

    DECLARE @Amount MONEY, @Term INT

    DECLARE @fRate float, @dRate decimal (38,13)

    SELECT @Amount = 1000000, @Term = 17*9*13*7

    SELECT @TERM

    SELECT @fRate = CONVERT(FLOAT, @Amount)/@Term,

    @dRate = CONVERT(DECIMAL(38,13), @Amount)/@Term

    SELECT @fRate, @fRate * @Term fAmount,

    @dRate, @dRate * @Term dAmount

    Normally, though, I like the code to be at least as resolute as Granny's dollar store 4 function calculator and will use a scale of at least 15.

    Checking your second example. Good list of prime numbers. 😀

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)