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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 wrong calculation
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

arkiboys
Flowing Fount of Yak Knowledge

1433 Posts

Posted - 10/15/2012 :  05:51:17  Show Profile  Reply with Quote
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

Pakistan
885 Posts

Posted - 10/15/2012 :  06:00:19  Show Profile  Visit lionofdezert's Homepage  Send lionofdezert a Yahoo! Message  Reply with Quote
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

India
52326 Posts

Posted - 10/15/2012 :  22:31:13  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

1433 Posts

Posted - 10/16/2012 :  00:35:03  Show Profile  Reply with Quote
Solved by not using a cursor.
Thanks
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000