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.
| 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. |
 |
|
|
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 pubsselect 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 |
 |
|
|
shijobaby
Starting Member
44 Posts |
|
|
|
|
|