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 2008 Forums
 Transact-SQL (2008)
 wrong calculation

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-10-15 : 05:51:17
Both the following select and set return correct values here

declare @Value decimal(20, 10) = 87.8764566
declare @ValuePrevious decimal(20, 10) = 86.48456540

select
((@Value - @ValuePrevious)/@ValuePrevious) * 100

set @ValueFinal = ((@Value - @ValuePrevious) / @ValuePrevious) * 100.0
print @ValueFinal

I am using a cursor with the above set statement
I can not see why in my cursor the set returns 0.0000000000
Do you see why please?

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2012-10-15 : 06:00:19
arki, you have to share your cursor code, as its hard to guess, whats actually missing ?

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-15 : 22:31:13
quote:
Originally posted by arkiboys

Both the following select and set return correct values here

declare @Value decimal(20, 10) = 87.8764566
declare @ValuePrevious decimal(20, 10) = 86.48456540

select
((@Value - @ValuePrevious)/@ValuePrevious) * 100

set @ValueFinal = ((@Value - @ValuePrevious) / @ValuePrevious) * 100.0
print @ValueFinal

I am using a cursor with the above set statement
I can not see why in my cursor the set returns 0.0000000000
Do you see why please?


please dont cross post

didnt you get solution here?

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=179760

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-10-16 : 00:35:03
Solved by not using a cursor.
Thanks
Go to Top of Page
   

- Advertisement -