5 posts

## T-SQL Guru wanted

Back to Forum: Tech Off
• 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.124523

(Which is what comes back from Excel)

Thanks,

Ian.

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

• 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.124523

(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 floatSET @Result = ( 14.278687 *( POWER( 1088644 * 2 ) , -0.1913)) - 1`

• Thanks!

• 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.

• 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.