If you are using Analytical Accounting and get the error which is something like "[Microsoft] [SQL Native Client] [SQL Server] Violation of PRIMARY KEY constraint 'PKAAG20003.' Cannot insert duplicate key in Object 'AAG20003'."
The table name could be different.
Your first steps should be to check out KB article "897280" which has a script to fix this error. This should solve the problem 90% of the times.
However, if you still get the error, this means the numbers are correct in the AAG00102 table and a duplicate key error is often caused by an invalid record in the AAG2000X series of tables.
Run the following script against your company database -
select * from AAG20000 where aaSubLedgerHdrId = 0
select * from AAG20001 where aaSubLedgerHdrId = 0
select * from AAG20002 where aaSubLedgerHdrId = 0
select * from AAG20003 where aaSubLedgerHdrId = 0
If you get any results - those are the entries causing the problem. The 0 in the aaSubLedgerHdrId is not a valid record since the next number needs to come from the AAG00102 table.
Hope that helps!