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)
 Sum issue

Author  Topic 

baze7
Yak Posting Veteran

58 Posts

Posted - 2010-04-05 : 17:09:51
Not sure if anyone can help, but I cannot get this sum to work properly:
sum ((ivn.price * ivn.qty_invoiced) - ((ivn.price * (ivn.qty_invoiced) * ivn.disc / 100))) / ((ivn.price * ivn.qty_invoiced) - (((ivn.price * (ivn.qty_invoiced) * ivn.disc / 100))) - (item.unit_cost * ivn.qty_invoiced))


If I do this:
sum ((ivn.price * ivn.qty_invoiced) - ((ivn.price * (ivn.qty_invoiced) * ivn.disc / 100)))

it is correct. If I do
sum((ivn.price * ivn.qty_invoiced) - (((ivn.price * (ivn.qty_invoiced) * ivn.disc / 100))) - (item.unit_cost * ivn.qty_invoiced))

it is fine, just putting the 2 together is the issue.

Thanks
Chad

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-05 : 17:13:10
Could you explain what happens?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

DBA in the making
Aged Yak Warrior

638 Posts

Posted - 2010-04-05 : 18:15:38
Are you sure you should be using SUM()? Perhaps you could explain what you have (table structure and sample data), and what you're trying to achieve.

There are 10 types of people in the world, those that understand binary, and those that don't.
Go to Top of Page

Asken
Starting Member

38 Posts

Posted - 2010-04-07 : 05:23:07
Divide by 100.0 instead of just 100...

A bit short maybe...

SELECT 1 / 100 = 0 -- integer division
SELECT 1 / 100.0 = 0.010000

Reporting & Analysis Specialist
Go to Top of Page
   

- Advertisement -