SQL - To the Power of -1

  • SQL DB

    I have a column called 'Rate', and I want to do a calculation whereby it does...

    'Rate' to the Power of -1

    Any idea's?

    Thanks

  • Hi,

    You can use the POWER function...

    POWER(CAST(rate AS FLOAT), -1)

    Hth



    Ade

    A Freudian Slip is when you say one thing and mean your mother.
    For detail-enriched answers, ask detail-enriched questions...[/url]

  • Equivalent to 1.0/Rate

    ____________________________________________________

    Deja View - The strange feeling that somewhere, sometime you've optimised this query before

    How to get the best help on a forum

    http://www.sqlservercentral.com/articles/Best+Practices/61537
  • Thanks, so for the following returned data:

    SELECT *

    FROM tblPandL

    WHERE Currency not like 'GBP'

    AND Currency not like 'ZAR'

    AND Date >= '04/08/08'

    order by date desc

    I want to run the power function, i would:

    UPDATEtblPandL

    POWER(CAST(rate AS FLOAT), -1)

    WHERE Currency not like 'GBP'

    AND Currency not like 'ZAR'

    AND Date >= '04/08/08'

    Thanks

  • If you wanted to update the rate using the power function you would:

    UPDATE tblPandL

    SET rate = POWER(CAST(rate AS FLOAT), -1)

    ...

    ...



    Ade

    A Freudian Slip is when you say one thing and mean your mother.
    For detail-enriched answers, ask detail-enriched questions...[/url]

  • :):D:):D:):D

    Thank you very very much!

  • Looking at the performance of 1.0/n against POWER(n, -1) it seems that there is negligible difference. For a run on a table of 500,000 rows, on my heap of junk, both statements took 13 seconds and had the same execution plan...



    Ade

    A Freudian Slip is when you say one thing and mean your mother.
    For detail-enriched answers, ask detail-enriched questions...[/url]

  • Thanks, I only have something like 700rows of data so it run quick for me!

    Thanks again!

Viewing 8 posts - 1 through 7 (of 7 total)

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