Here is my original query:
I get the following error:
Multiple columns are specified in an aggregated expression containing an outer reference. If an expression being aggregated contains an outer reference, then that outer reference must be the only column referenced in the expression.
Well that is a strange limitation.
So I created a less efficient version of the query to get around the limitation:
Whereas the 2nd query works, I wince at the redundancy. Does anyone have suggestions?
Code:
UPDATE #AdjustedPremium
SET AdjustedNetPremium = c.NetPremium
FROM #AdjustedPremium a
INNER JOIN AccountCurrent b ON a.AccountCurrentID = b.AccountCurrentID
INNER JOIN #PremiumFinancialTemp c ON
b.ProductCode = 'CHIRO1'
AND b.BookDate = '1/31/2010'
AND b.Revised = 'N'
AND b.Reference = c.Reference
AND a.AdjustedTransactionCode = c.TransactionCode
AND b.TransactionEffectiveDate = c.TransactionEffectiveDate
WHERE a.TimeProcessed IS NULL
AND ABS(b.NetPremium - c.NetPremium) <= 5
AND ABS(b.NetPremium - c.NetPremium) = (
SELECT MIN(ABS(b.NetPremium - d.NetPremium))
FROM #PremiumFinancialTemp d
WHERE b.Reference = d.Reference
AND a.AdjustedTransactionCode = d.TransactionCode
AND b.TransactionEffectiveDate = d.TransactionEffectiveDate )
Multiple columns are specified in an aggregated expression containing an outer reference. If an expression being aggregated contains an outer reference, then that outer reference must be the only column referenced in the expression.
Well that is a strange limitation.
So I created a less efficient version of the query to get around the limitation:
Code:
UPDATE #AdjustedPremium
SET AdjustedNetPremium = c.NetPremium
FROM #AdjustedPremium a
INNER JOIN AccountCurrent b ON a.AccountCurrentID = b.AccountCurrentID
INNER JOIN #PremiumFinancialTemp c ON
b.ProductCode = 'CHIRO1'
AND b.BookDate = '1/31/2010'
AND b.Revised = 'N'
AND b.Reference = c.Reference
AND a.AdjustedTransactionCode = c.TransactionCode
AND b.TransactionEffectiveDate = c.TransactionEffectiveDate
WHERE a.TimeProcessed IS NULL
AND ABS(b.NetPremium - c.NetPremium) <= 5
AND ABS(b.NetPremium - c.NetPremium) = (
SELECT MIN(ABS(d.NetPremium - e.NetPremium))
FROM AccountCurrent d
INNER JOIN #PremiumFinancialTemp e ON
d.Reference = e.Reference
AND a.AdjustedTransactionCode = e.TransactionCode
AND d.TransactionEffectiveDate = e.TransactionEffectiveDate
WHERE d.AccountCurrentId = b.AccountCurrentId )