sundemo


I don't know if this is a right place for this kind of question, but here we go...

I have a function that gets string ("2/3*(1500.0000+(-218.3300)+(-89.7000)+(-24.0000)-585.0000)"). Problem is that this returns 0:

select 2/3*(1500.0000+(-218.3300)+(-89.7000)+(-24.0000)-585.0000)

This gives right answer:

select 2.0/3.0*(1500.0000+(-218.3300)+(-89.7000)+(-24.0000)-585.0000)

Is there easy way to fix this




Re: Calculating total from string

Madhu K Nair


check the datatype used for the parameter/calculation... if it is integer change to float

Madhu







Re: Calculating total from string

Jens K. Suessmeyer

Hi,

you will have to CAST the integer values to decimal types vefore calculating, otherwise SQL Server will assume that the result will be integer as well, calculating everything using the integer type.

HTH, Jens K. Suessmeyer.

---
http://www.sqlserver2005.de
---





Re: Calculating total from string

sundemo

No that's not the point...

SELECT 2/3 returns also 0 if you write it in Query Analyzer.





Re: Calculating total from string

sundemo

And there is no other ways to do it in sql server



Re: Calculating total from string

Madhu K Nair

check this

declare @i1 int

declare @i2 int

declare @i3 int

declare @d1 float

declare @d2 float

declare @d3 float

Set @d1=2

Set @d2=3

set @d3=@d1/@d2

print @d3

Set @i1=2

Set @i2=3

set @i3=@i1/@i2

print @i3

Madhu






Re: Calculating total from string

sundemo

Yes I understand what you mean, but I have only one parameter (string) that includes formula. This formula can be short or very long... example 100+100*9*(100/0.608-100) and so on...