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
 decimals

Author  Topic 

jjmoss1234
Starting Member

11 Posts

Posted - 2009-12-02 : 05:09:16
If I do a standard sum in SQL 2005, SELECT 821 / 825 * 100, I get the result of 0. is there a way I can get the required result which is 99.5? many thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-12-02 : 05:33:19
select 821.0 / 825 * 100

or

select 821 * 100.0 / 825


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

kbhere
Yak Posting Veteran

58 Posts

Posted - 2009-12-02 : 05:46:04
SELECT 1.0 * 821 / 825 * 100;

Multiply the value with 1.0
Value multiplied by 1 will always same..


Balaji.K
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-02 : 08:11:52
Here is the reason
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx

Madhivanan

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

jjmoss1234
Starting Member

11 Posts

Posted - 2009-12-02 : 12:14:21
Thankyou very much Madhivanan
This turned out to be the reason, I added a float conversion and all is now well!!

Many thanks

John
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-03 : 01:13:28
quote:
Originally posted by jjmoss1234

Thankyou very much Madhivanan
This turned out to be the reason, I added a float conversion and all is now well!!

Many thanks

John


You are welcome

Madhivanan

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

- Advertisement -