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)
 Cannot perform aggregate if there is subquery

Author  Topic 

ryanlcs
Yak Posting Veteran

62 Posts

Posted - 2010-01-03 : 20:39:30
Hi

I have a query that will contain aggregate function, but within the statement, I need a sub-query, but it will throws me a error. Saying "Cannot perform an aggregate function on an expression containing an aggregate or a subquery."

How can I get this fix?

Select case when sum(case when Tester <> 'Overall' and Channel IN
(Select Channel From TABLE1
Where Description = 'TOP' and Channel_Group = 'H1')

then tester_count else 0 end ) > 0 then sum(case when Tester= 'Overall'
and Channel = 'H1' then channel_Qty else 0 end )
else Null end as 'RESULT'
from TABLE2

Thank You.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-01-03 : 22:42:49
Just join to table1 instead, looks like you may be able to join on Channel column.

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

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -