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)
 Derived Table

Author  Topic 

Paul.Ilacqua
Starting Member

1 Post

Posted - 2009-01-12 : 12:26:52
In the following TSQL from SQL 2005 I want to get the sum of the
I get the following

Cannot perform an aggregate function on an expression containing an aggregate or a subquery.
I believe it's << Sum(SUM(B.QTY) * BF.BOM_QTY)>> this that is causing the error. How can I pull that value into an outer query so I can sum it?

=============================================
SELECT
BF.PART
,Sum(SUM(B.QTY) * BF.BOM_QTY) AS CONSUMED
FROM BUILDS B
INNER JOIN V_BACK_FLUSH_BOM BF
ON BF.ASSEMBLYID = B.ASSEMBLY_ID
where part = '37220004'
GROUP BY BF.PART,BF.BOM_QTY
=============================================

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-12 : 12:34:42
MAY BE THIS

select BF.PART,sum(CONSUMED)
from
(
SELECT
BF.PART,
SUM(B.QTY) * BF.BOM_QTY AS CONSUMED
FROM BUILDS B
INNER JOIN V_BACK_FLUSH_BOM BF
ON BF.ASSEMBLYID = B.ASSEMBLY_ID
where part = '37220004'
GROUP BY BF.PART,BF.BOM_QTY
)T
group by BF.PART
Go to Top of Page
   

- Advertisement -