Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 use or code the POWER function when value nagative

Author  Topic 

Manothinakaran
Starting Member

8 Posts

Posted - 2010-12-05 : 21:55:31
Dear Guru,
I need a huge favour..
how do you use or code the POWER function when the value is negative?

I'm receiving the error as below:
Msg 3623, Level 16, State 1, Line 1
A domain error occurred.

I realized that the value that I was passing was negative.
For example: select (POWER(-0.37,.5))

So how do you use or code the POWER function when the value is negative?

Please help dear gurus..

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-12-05 : 22:32:46
Are you looking for this:

Declare @x numeric(5,2)
Set @x = -0.37

Select Case when @x <0 then POWER(@x * -1,.5) else POWER(@x,.5) end
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-12-06 : 00:09:19
select (POWER(ABS(-0.37),.5))

PBUH

Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-12-06 : 00:10:16
The power function only returns real numbers, but raising a number to the .5 power is the same as the square root, and the square root of a negative number is a complex number.

You can only raise negative numbers to a whole power with the POWER function.



CODO ERGO SUM
Go to Top of Page
   

- Advertisement -