here is the query:
===========================================================
select
@NextWeek01=IsNull(Sum(Case When Year(InvoiceDate)=(select (Year(frcstDate)-1) from SISLogic..SIS_MRPDates where frcstIndex = @CrossIndex) Then ExtendedAmount Else 0 End),0)
from SISReports..vu_SISInvoices
where Item = @ItemNum
===========================================================
I keep getting the error:
Error 130: Cannot perform an aggregate function on an expression containing an aggregate or subquery.
I Understand why the error is there, I just can't really think of another way to do this query.
Basically what I want is to get a sum sales (ExtendedAmount)from my Inovices where the year (InvoiceDate) is a year earlier than the Forecasted year (frcstDate), but to get the Forecasted year I have to go to a lookup table (SIS_MRPDates).
I cannot change the layout of the tables, so I'll have to grab this information through a query...The above query should give me the required results, except it won't work
Thanks for any help
===========================================================
select
@NextWeek01=IsNull(Sum(Case When Year(InvoiceDate)=(select (Year(frcstDate)-1) from SISLogic..SIS_MRPDates where frcstIndex = @CrossIndex) Then ExtendedAmount Else 0 End),0)
from SISReports..vu_SISInvoices
where Item = @ItemNum
===========================================================
I keep getting the error:
Error 130: Cannot perform an aggregate function on an expression containing an aggregate or subquery.
I Understand why the error is there, I just can't really think of another way to do this query.
Basically what I want is to get a sum sales (ExtendedAmount)from my Inovices where the year (InvoiceDate) is a year earlier than the Forecasted year (frcstDate), but to get the Forecasted year I have to go to a lookup table (SIS_MRPDates).
I cannot change the layout of the tables, so I'll have to grab this information through a query...The above query should give me the required results, except it won't work
Thanks for any help