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 2000 Forums
 Transact-SQL (2000)
 Cannot perform an aggregate function on an expression contai

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-01-14 : 13:30:19
Ryan writes "Is there a workaround for the following select statement?


SELECT

SUM(CASE WHEN M.Product_Line IN (select * from ipgq) THEN M.FCF0_Q4 + M.FDF0_Q4 ELSE 0 END) AS FY05Q4_IPGP


It produces the following error:

Cannot perform an aggregate function on an expression containing an aggregate or a subquery."

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2006-01-15 : 11:37:28
Ugh. Please post your whole query and we can show you a better (faster) way of handling this.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-01-15 : 18:26:46
You can probably do what you need with a LEFT JOIN in order to remove the subquery from the CASE. The code below uses data from the pubs database to show how it can be done.

use pubs

select
sum (
case
when a.au_id = b.au_id
then a.zip +right(a.au_id,4)
else 0 end
)
from
authors a
left join
(
select
distinct
bb.au_id
from
authors bb
where
bb.au_lname like 'd%'
) b
on a.au_id = b.au_id






CODO ERGO SUM
Go to Top of Page

shijobaby
Starting Member

44 Posts

Posted - 2009-08-21 : 06:19:00
The ways to avoid this error is simple

just look into my post


http://sqlerrormessages.blogspot.com/2009/08/sql-server-error-message-msg-130-cannot.html
Go to Top of Page
   

- Advertisement -