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 2005 Forums
 Transact-SQL (2005)
 Getting incorrect - Running Total

Author  Topic 

kellog1
Starting Member

35 Posts

Posted - 2010-08-16 : 16:50:09
Guys,
I am trying to calculate running totals and I am getting incorrect results. Below is my query...

select PublicationId,ProjectPublicationId, ControlFundingAmount,
(select sum(ControlFundingAmount)
from DimProjectPublication pp1
where pp1.ProjectPublicationId = pp.ProjectPublicationId
and pp1.PublicationId = pp.PublicationId)
from DimProjectPublication pp
where ProjectPublicationId IN (135750,135211)
order by ProjectPublicationId

Result:
PublicationId ProjectPublicationId ControlFundingAmount RT
43 135211 200000.00 200000.00
43 135750 150000.00 150000.00

Desired Result:
PublicationId ProjectPublicationId ControlFundingAmount RT
43 135211 200000.00 200000.00
43 135750 150000.00 350000.00

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-08-16 : 19:32:30
Cross posting is irritating, but it does get my post count up!

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -