Home Forums SQL Server 2008 T-SQL (SS2K8) Error: Each GROUP BY expression must contain at least one column that is not an outer reference. RE: Error: Each GROUP BY expression must contain at least one column that is not an outer reference.

  • It may be that you haven't defined MDEP within the select - it's having to call all the way up to the UPDATE statement to find it, and that's outside of the GROUP range. What happens if you add MDEP into the the query, like this:

    Update MDEP

    Set MDEP.POObligations =

    (

    select SUM(PerPO.SumOfPurchaseOrder) from

    (

    Select PO_MX.PONumber, PO_MX.MDEP, ((PO_MX.PaymentPosted * -1 ) + POD.SumOfLineItems) * (cast(PO_MX.PrimarySplit as decimal(5,2))/100) As SumOfPurchaseOrder

    from PO_MX

    inner join

    (

    select PONumber, SUM(PO_DX.QuantityOrdered * PO_DX.Price) As SumOfLineItems

    from PO_DX

    join MDEP ON PO_MX.MDEP = MDEP.MDEP --add MDEP as a join here

    where (QuantityOrdered * Price) is not NULL

    group by PO_DX.PONumber

    )

    as POD

    on PO_MX.PONumber = POD.PONumber

    --where PO_MX.MDEP = MDEP.MDEP --move this to the ON clause above

    )

    as PerPO

    )

    where MDEP.MDEP In

    (select MDEP from PO_MX)