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
 problem with POWER(x,y) in sql

Author  Topic 

luzippu
Starting Member

23 Posts

Posted - 2006-05-08 : 06:52:57
hi,

i can't see why the following field is not working correctly, ie: it's always coming up with 0:

((POWER((1+((((((POWER((1+(dbo_table1.APR/100)),(1/12)))-1))*12))/12)), dbo_table1.FREQUENCY)-1)*(12/dbo_table1.FREQUENCY))*100 AS YIELD

breaking the code down to a smaller formula it does work.

it looks like i can't have more calculations/references inside a POWER(x,y) function.

any comments would be appreciated.

thank you

nr
SQLTeam MVY

12543 Posts

Posted - 2006-05-08 : 06:59:51
Try putting .0 after everything

((POWER((1.0+((((((POWER((1.0+(dbo_table1.APR/100.0)),(1.0/12.0)))-1.0))*12.0))/12.0)), dbo_table1.FREQUENCY)-1.0)*(12.0/dbo_table1.FREQUENCY))*100.0 AS YIELD

If that doesn't help then look at the individual expressions to see if they are returning what you expect.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

luzippu
Starting Member

23 Posts

Posted - 2006-05-08 : 09:06:24
thanks very much nr, your solution has worked correctly.

must say, however, a bit strange that 1 is different from 1.0 ...

thanks again
luzippu
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-05-08 : 09:09:02
it is as one is treated as interger and other is treated as numeric/decimal.

Go with the flow & have fun! Else fight the flow
Blog thingie: [URL="http://weblogs.sqlteam.com/mladenp"]
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2006-05-08 : 10:40:12
1/2 = 0 (result is an integer)
1.0/2 = .5 (result is a numeric)

It gets the precision of the result from the input values and truncates/rounds as appropriate (or not).

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -