Tech Off Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

T-SQL Guru wanted

Back to Forum: Tech Off
  • User profile image
    Ian

    Hi,

    Does anyone know how the folowing equation (from Excel) would be represented in T-SQL?

    =(14.278687*((1088644*2)^-0.1913))-1

    (The bit I am not sure about is the ^ operator for exponentiation?).

    The result should equal something like:

    -0.124522547

    (Which is what comes back from Excel)


    Thanks,




    Ian.

    select ( 14.278687 *( POWER( 1088644.00000000 * 2.000000000 , -0.1913))) - 1

  • User profile image
    W3bbo

    Ian wrote:
    Hi,

    Does anyone know how the folowing equation (from Excel) would be represented in T-SQL?

    =(14.278687*((1088644*2)^-0.1913))-1

    (The bit I am not sure about is the ^ operator for exponentiation).

    The result should equal something like:

    -0.124522547

    (Which is what comes back from Excel)


    the POWER(numeric_expression, y) function, alternatively the EXP(float_expression) function that returns the exponential value.

    So in T-SQL you might want something like this:

    DECLARE @Result float
    SET @Result = ( 14.278687 *( POWER( 1088644 * 2 ) , -0.1913)) - 1

  • User profile image
    Ian

    Thanks!

  • User profile image
    julianv23

    The T-SQL you have to use is

    select 14.278687 * power((1088644.0000000000000000*2),-0.1913) - 1

    note the number of zero's after the decimal, you need to do that for the POWER function when a fractional result is being returned as the result value will be the same data type as the input value.

  • User profile image
    Human​Compiler

    I'd like to pose the question: Why are you doing all this math in t-sql?  I'm sure there's definitely times you'd need to, but I'm curious exactly what you're doing to where you need to do this in t-sql.

    Sorry, had to ask.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.