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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Formula has different results in SQL

Author  Topic 

Crotalus
Starting Member

16 Posts

Posted - 2008-01-09 : 12:44:18
I use this formula in access, vb and excel to calculate the antilog of a number, but it doesn't work at all in SQL.

10^(Y/10)=Z

For example
in access, 10^(22/10) = 158.489319246111
in SQL, 10^(22/10) = 8

any ideas on how to make it work in SQL?

Thanks,
Ron

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-01-09 : 12:51:50
select power(10.0,(22.0/10.0))


elsasoft.org
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-09 : 12:53:54
Try POWER(10.0,(22.0/10.0))
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-10 : 02:08:07

This would explain the reason
select 22/10 as only_integer_part, 22.0/10 as exact_value

and if you used variables then you need to multiply it by 1.0

Declare @n1 int, @n2 int
select @n1=22,@n2=10
select @n1/@n2 as only_integer_part, @n1*1.0/@n2 as exact_value


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Crotalus
Starting Member

16 Posts

Posted - 2008-01-10 : 10:03:58
Thanks for the replies. I did try that "power" formula once before and it didn't work either. But I did get it to work with this:

EXP(Convert(real,Y)/10*LOG(10))

I don't know why that works, but it seems that it is very important for "Y" to be a real number.

The "power" formula might work as well, once I convert Y to real.

Ron
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-01-10 : 10:51:26
incidentally, the reason ^ wasn't working for you is because it has a different meanign in t-sql. it's the bitwise xor operator.

http://msdn2.microsoft.com/en-us/library/ms190277.aspx


elsasoft.org
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-11 : 01:28:54
<<
but it seems that it is very important for "Y" to be a real number.
>>

Yes as I explained

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2008-01-12 : 21:38:52
The symbol "^" does NOT mean raise to a power in SQL Server... it means XOR

--Jeff Moden
Go to Top of Page
   

- Advertisement -