Failure 3568 Cannot nest aggregate operations

Database
Enthusiast

Failure 3568 Cannot nest aggregate operations

Hi,

I have a problem with this part of my code:

(SUM(CASE WHEN PII.O_Id IS NULL THEN 

(CASE WHEN PII.B_Qty< 1 THEN

(ZEROIFNULL(ABS(PII.B_Amt) *(-1) ) +

SUM( CASE WHEN (pd.Disc_cd NOT IN('A','B','F','V')) 

THEN(CASE WHEN ((PII.B_Qty=0) OR (PII.B_Qty<0)) THEN pd.disc_amt ELSE 0 END) ELSE 0 END ) ) 

ELSE (ABS(PII.B_Amt) +

SUM(CASE WHEN (pd.Disc_cd NOT IN('A','B','F','V'))

THEN(pd.Disc_amt*(-1)) ELSE 0 END) ) 

END )

ELSE 0 END)) AS My_amt

(here PII,pd etc are tables)

the error is : *** Failure 3568 Cannot nest aggregate operations.

Could anyone pls point out where the error is ? Any help would be appreciated.

2 REPLIES
Supporter

Re: Failure 3568 Cannot nest aggregate operations

It would be much easier if you format your code in a way that the structure can be understand.

But the error message should give you an hint - you can not build a sum on a sum within one statement.

so check if you find something like sum( ...sum(...))

Supporter

Re: Failure 3568 Cannot nest aggregate operations

funny reply - you need to avoid them as otherwise you will not get a result as the syntax is not supported.

But to help you much more details would be required. Are you group this? What should the different summs express? 

And as stated above I have very limited passion to reformat this for you to get a clue what you want to achive.