Identifying Duplicate Transactions
From the Useful SQL Scripts Series.
Because Microsoft Dynamics GP is designed to have separate tables for WORK, OPEN and HISTORY transactions, there are times where it is possible for a transaction record to exist in more than one table. This is usually the result of an error or interruption.
These duplicate records become an issue when it comes time to move a transaction from one table to another. For example: when it is posted, fully applied, or paid transaction removal is used. At this time, the duplicate will generate a duplicate key error and the process will be aborted.
Another time when duplicate records can cause problems is when using an Inquiry window which can show data from more than one of the WORK, OPEN and HISTORY tables at the same time. To achieve this, the Inquiry windows transfer data into a single temporary table and use this table for their display. If duplicate records exist, you will get an error when the data is being copied into the temporary table.
An error message that may be generated by several inquiry windows, when there are duplicates, refers to a createSQLTmpTable stored procedure. This stored procedure does not actually exist, but is in fact referring to pass through SQL script called from the Dexterity code. For example: The error message from the Payables Transaction Inquiry window is
The stored procedure createSQLTmpTable returned the following results: DBMS: 2627, Microsoft Dynamics GP: 0.
Note: Error 2627 is a SQL Cannot insert duplicate key error.
To make it easier to find duplicates, I am providing the following SQL queries to look for duplicate headers in the core Distribution and Financial modules. While these will not find every possible duplicate in every table, they are a great basis for checking for duplicate transactions.
SQL Script to look for duplicate headers in SOP, IVC, POP, RM, PM, IV, & GL modules
-- SOP Duplicates
select SOPTYPE, SOPNUMBE, COUNT(*) as [COUNT] from
(
select SOPTYPE, SOPNUMBE from SOP10100 W
UNION ALL
select SOPTYPE, SOPNUMBE from SOP30200 H
) C
group by SOPTYPE, SOPNUMBE
having COUNT(*) > 1
-- IVC Duplicates
select DOCTYPE, INVCNMBR, COUNT(*) as [COUNT] from
(
select DOCTYPE, INVCNMBR from IVC10100 W
UNION ALL
select DOCTYPE, INVCNMBR from IVC30101 H
) C
group by DOCTYPE, INVCNMBR
having COUNT(*) > 1
-- POP PO Duplicates
select PONUMBER, COUNT(*) as [COUNT] from
(
select PONUMBER from POP10100 W
UNION ALL
select PONUMBER from POP30100 H
) C
group by PONUMBER
having COUNT(*) > 1
-- POP Receivingss Duplicates
select POPRCTNM, COUNT(*) as [COUNT] from
(
select POPRCTNM from POP10300 W
UNION ALL
select POPRCTNM from POP30300 H
) C
group by POPRCTNM
having COUNT(*) > 1
-- RM Duplicates
select RMDTYPAL, DOCNUMBR, COUNT(*) as [COUNT] from
(
select RMDTYPAL, RMDNUMWK as DOCNUMBR from RM10301 W
UNION ALL
select RMDTYPAL, DOCNUMBR from RM10201 W
UNION ALL
select RMDTYPAL, DOCNUMBR from RM20101 O
UNION ALL
select RMDTYPAL, DOCNUMBR from RM30101 H
) C
group by RMDTYPAL, DOCNUMBR
having COUNT(*) > 1
-- PM Duplicates
select DOCTYPE, VCHRNMBR, COUNT(*) as [COUNT] from
(
select DOCTYPE, VCHNUMWK as VCHRNMBR from PM10000 W
UNION ALL
select DOCTYPE, VCHRNMBR from PM10300 P
UNION ALL
select DOCTYPE, VCHRNMBR from PM10400 M
UNION ALL
select DOCTYPE, VCHRNMBR from PM20000 O
UNION ALL
select DOCTYPE, VCHRNMBR from PM30200 H
) C
group by DOCTYPE, VCHRNMBR
having COUNT(*) > 1
-- IV Duplicates
select IVDOCTYP, DOCNUMBR, COUNT(*) as [COUNT] from
(
select IVDOCTYP, IVDOCNBR as DOCNUMBR from IV10000 W
UNION ALL
select IVDOCTYP, DOCNUMBR from IV30200 H
) C
group by IVDOCTYP, DOCNUMBR
having COUNT(*) > 1
-- GL Duplicates
select JRNENTRY, RCTRXSEQ, SEQNUMBR, ACTINDX, TRXDATE, CRDTAMNT, DEBITAMT, [YEAR], COUNT(*) as [COUNT] from
(
select WH.JRNENTRY, WH.RCTRXSEQ, WL.SQNCLINE as SEQNUMBR, WL.ACTINDX, TRXDATE, CRDTAMNT, DEBITAMT, WH.OPENYEAR as [YEAR] from GL10000 WH JOIN GL10001 WL ON WL.JRNENTRY = WH.JRNENTRY
UNION ALL
select JRNENTRY, RCTRXSEQ, SEQNUMBR, ACTINDX, TRXDATE, CRDTAMNT, DEBITAMT, OPENYEAR as [YEAR] from GL20000 O
UNION ALL
select JRNENTRY, RCTRXSEQ, SEQNUMBR, ACTINDX, TRXDATE, CRDTAMNT, DEBITAMT, HSTYEAR as [YEAR] from GL30000 H
) C
group by JRNENTRY, RCTRXSEQ, SEQNUMBR, ACTINDX, TRXDATE, CRDTAMNT, DEBITAMT, [YEAR]
having COUNT(*) > 1
Once the duplicate records have been identified, you will need to use SQL queries to check which of the transactions are the correct ones. Sometimes a duplicate transaction only has the key fields entered and the rest of the fields are blank and/or there are no line records associated with the header.
Once you have identified what is the incorrect data and have made a backup, you can remove the duplicate data using Transact-SQL commands.
The script is also available as an attachment at the bottom of this post.
You might also want to look at the Automated Solutions, the links are at the bottom of the General Articles & Links page.
Let me know if you find this useful.
David
Comments
Anonymous
December 01, 2008
Posting from the Dynamics GP Blogster http://dynamicsgpblogster.blogspot.com/2008/12/sql-mania-series-at-developing-for.htmlAnonymous
December 05, 2008
Posting from Vaidy Mohan's Blog http://www.vaidy-dyngp.com/2008/12/davids-sql-series-identifying-duplicate.htmlAnonymous
December 07, 2008
I just wanted to take a second and highlight again David Musgrave's very useful SQL Scripts SeriesAnonymous
December 07, 2008
The comment has been removedAnonymous
December 10, 2008
By David Musgrave http://blogs.msdn.com/developingfordynamicsgp/archive/2008/12/05/identifying-duplicate-transactions.aspxAnonymous
December 10, 2008
Based on the success of the "Resolving Security Issues in Dynamics GP" located here, MicrosoftAnonymous
January 14, 2009
There is a similar message you can get that refers to createTmpTable rather than createSqlTmpTable when dealing with financial series inquiry windows. However, the same applies in that the stored proc mentioned does not actually exist, but is pass thru sql code that is causing the error. "The stored procedure createTmpTable returned the following results" DBMS: 12, Microsoft Dynamics GP 0." See KB 852594. Error 12 possibly means the table cannot be created or accessed within the tempdb database.Anonymous
January 19, 2009
One of my users received a somewhat similar message when doing a Payables Transaction Inquiry in Dynamics GP 9 running on SQL Server 2000. The exact error was: "The stored procedure createSQLTmpTable returned the following results: DBMS: 12, Microsoft Dynamics GP: 0". Searches of the CustomerSource knowledge base, the Dynamics community forums and Google have been fruitless. I don't know what DBMS error 12 means. I couldn't even find a reference to that error in the Books Online for SQL Server 2000. Naively, we restarted Dynamics and tried the inquiry again. This time the inquiry worked. However, I would like to know more about what caused the error and how to permanently fix it or prevent it from happening. We tend to see it a few times a week, for a few users.Anonymous
January 19, 2009
Many of inquiry windows in Microsoft Dynamics GP have been optimized to leverage SQL Server to increaseAnonymous
January 19, 2009
Many of inquiry windows in Microsoft Dynamics GP have been optimized to leverage SQL Server to increaseAnonymous
November 02, 2009
I found it very useful, specially in fixing those transactions with posting interruption problems.Anonymous
July 20, 2010
This is very useful for us David...Thanx a lot :)Anonymous
January 10, 2013
I also encounter that error now running on GP2010 only one customer cause this problem while the rest all ok. I also tried to run all most all of the sql from internet including the above, unfortunately i couldn't find any result. what i have notice is the error occur while it creating Stored procedures. please help me.Anonymous
January 10, 2013
Kristen Sounds like you might have a related but different issue. You might want to ask on the forums or log a support case. DavidAnonymous
February 25, 2013
Posting by Mark Polino at DynamicAccounting.net msdynamicsgp.blogspot.com/.../dynamics-gp-land-finding-duplicate-gl.htmlAnonymous
December 17, 2013
Thanks, good and effective solutionAnonymous
February 01, 2015
Hello David. I'm facing the duplicate key violation error in ;MOP1009' Table can u help to correct it.Anonymous
June 09, 2015
Thanks David! This is very helpful... I wanted to add two more scripts for Field Service Contracts and RMA's. It does seem like the Contract module does allow duplicate Contract Numbers in the History table (SVC30600) so I had to select DISTINCT there because I think you can create a new Contract using the same number as the old Contract. -- CONTRACT DUPLICATES -- added by DF select CONTNBR, CONSTS, COUNT() as [COUNT] from ( select CONTNBR, CONSTS from SVC00600 W UNION ALL select DISTINCT CONTNBR, CONSTS from SVC30600 H ) C GROUP BY CONTNBR, CONSTS HAVING COUNT() > 1 -- RMA DUPLICATES select RETDOCID, COUNT() as [COUNT] from ( select RETDOCID from SVC05000 W UNION ALL select RETDOCID from SVC35000 H ) C GROUP BY RETDOCID HAVING COUNT() > 1Anonymous
October 27, 2015
This script found my duplicate trx...worked like a charm! Thank you so much!Anonymous
October 28, 2015
Hi Theresa Glad that it worked for you. DavidAnonymous
May 05, 2016
Dave, this was great and very useful to resolve a duplicate key issue the OPO Receiving tables. I will be sure to keep this handy.Thank you for the SQL Scripts it was very helpful!