Nth root of a number

  • Hi,

    I am trying to calculate CAGR which when computed for two years, the formula is (Annual Turnover ^ 1/2)-1 and when computed for three years, the formula is (Annual Turnover ^1 / 3)-1 and when computed for four years, the formula is (Annual Turnover ^ 1/4)-1.

    So, Can anybody suggest me how we can get the nth root of a number in SQL? I tried using power(Annual Turnover,(1/n)). It doesn't work.

    Thanks in advance,

    Valli

  • 3rd root of 27 is calculated as (the positive value)

    SELECT POWER(27.0E, 1.0E / 3.0E)


    N 56°04'39.16"
    E 12°55'05.25"

  • See this post: http://www.sqlservercentral.com/Forums/Topic239436-8-1.aspx

    Not sure how you are doing your calcs, but the script below will take the 2nd, 3rd, 4th and 5th root of the number 27.

    DECLARE

    @nthRoot INT

    ,@AnnualTurnover INT

    ,@x INT

    SET @AnnualTurnover = 27

    SET @x = 2

    WHILE @x <= 5

    BEGIN

    SET @nthRoot = @x

    SELECT

    @AnnualTurnover '@AnnualTurnover'

    ,@nthRoot 'nthRoot'

    ,POWER(CAST(@AnnualTurnover AS FLOAT),(CAST(1 AS FLOAT)/CAST(@nthRoot AS FLOAT))) 'Result'

    SET @x = @x + 1

    END

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply