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 sum

Author  Topic 

crugerenator
Posting Yak Master

126 Posts

Posted - 2008-02-01 : 12:08:30
convert(decimal(15,1),(sum(isnull(pe.org_own_assets_ext,0)))+(sum(isnull(pe2.org_own_assets_ext,0)))) as total_assets

I think the problem is with the + sign, maybe?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-02-01 : 12:09:58
What error is reported by SQL Server?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-02-01 : 12:13:13
What is the problem? There doesn't seem to generate any errors.

select
convert(decimal(15,1),(sum(isnull(pe.org_own_assets_ext,0)))
+(sum(isnull(pe2.org_own_assets_ext,0)))) as total_assets
from (select 1 as org_own_assets_ext) pe
join (select 1 as org_own_assets_ext) pe2 on 1=1

output:
total_assets
-----------------
2.0


Be One with the Optimizer
TG
Go to Top of Page

crugerenator
Posting Yak Master

126 Posts

Posted - 2008-02-01 : 12:14:41
There actually is no error...

It's just not doing the math right.

Here's an example:

The value in pe.org_own_assets_ext = 36189.5
The value in pe2.org_own_assets_ext = 277.10

I am getting 303764.6

I should be getting 36466.6

Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-02-01 : 12:20:31
You must have an error in your JOIN criteria, looks like some rows are getting "crossed up"

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -