Hello,
I am trying to develop a query that will delete a duplicate record and keep the original record. I have developed a select query that works. It does identify the duplicated records properly. But when I change it to a delete query the totals row goes away and I can't figure out how to set the criteria to Max(ID), I have tried Max([ID]) in the criteria section but I get the error Cannot have aggregate function in Where clause(tmp_MthStatsBaaPos.ID = Max(ID) and tmp_MthStatsBaaPos.BillMonthEnc in. Any help is appreciated.
Tom
I am trying to develop a query that will delete a duplicate record and keep the original record. I have developed a select query that works. It does identify the duplicated records properly. But when I change it to a delete query the totals row goes away and I can't figure out how to set the criteria to Max(ID), I have tried Max([ID]) in the criteria section but I get the error Cannot have aggregate function in Where clause(tmp_MthStatsBaaPos.ID = Max(ID) and tmp_MthStatsBaaPos.BillMonthEnc in. Any help is appreciated.
Tom
Code:
DELETE tmp_MthStatsBaaPos.ID, tmp_MthStatsBaaPos.BillMonthEnc, tmp_MthStatsBaaPos.POS, tmp_MthStatsBaaPos.[SumOfCountOfCase #], tmp_MthStatsBaaPos.SumOfSumOfUnits, tmp_MthStatsBaaPos.[SumOfCountOfOR Flag], tmp_MthStatsBaaPos.[SumOfSumOfOR Units], tmp_MthStatsBaaPos.SumOfSumOfAmt, tmp_MthStatsBaaPos.SumOfSumOfTotpay, tmp_MthStatsBaaPos.SumOfSumOfTotadj, tmp_MthStatsBaaPos.SumOfSumOfCurBal, tmp_MthStatsBaaPos.ARDays, tmp_MthStatsBaaPos.Last3MonChgs
FROM tmp_MthStatsBaaPos
WHERE (((tmp_MthStatsBaaPos.ID)=Max([ID])) AND ((tmp_MthStatsBaaPos.BillMonthEnc) In (SELECT [BillMonthEnc] FROM [tmp_MthStatsBaaPos] As Tmp GROUP BY [BillMonthEnc],[POS],[SumOfCountOfCase #],[SumOfSumOfUnits],[SumOfCountOfOR Flag],[SumOfSumOfOR Units],[SumOfSumOfAmt],[SumOfSumOfTotpay],[SumOfSumOfTotadj],[SumOfSumOfCurBal] HAVING Count(*)>1 And [POS] = [tmp_MthStatsBaaPos].[POS] And [SumOfCountOfCase #] = [tmp_MthStatsBaaPos].[SumOfCountOfCase #] And [SumOfSumOfUnits] = [tmp_MthStatsBaaPos].[SumOfSumOfUnits] And [SumOfCountOfOR Flag] = [tmp_MthStatsBaaPos].[SumOfCountOfOR Flag] And [SumOfSumOfOR Units] = [tmp_MthStatsBaaPos].[SumOfSumOfOR Units] And [SumOfSumOfAmt] = [tmp_MthStatsBaaPos].[SumOfSumOfAmt] And [SumOfSumOfTotpay] = [tmp_MthStatsBaaPos].[SumOfSumOfTotpay] And [SumOfSumOfTotadj] = [tmp_MthStatsBaaPos].[SumOfSumOfTotadj] And [SumOfSumOfCurBal] = [tmp_MthStatsBaaPos].[SumOfSumOfCurBal])));