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.
-- SOP Duplicatesselect SOPTYPE, SOPNUMBE, COUNT(*) as [COUNT] from (select SOPTYPE, SOPNUMBE from SOP10100 WUNION ALLselect SOPTYPE, SOPNUMBE from SOP30200 H) Cgroup by SOPTYPE, SOPNUMBEhaving COUNT(*) > 1
-- IVC Duplicatesselect DOCTYPE, INVCNMBR, COUNT(*) as [COUNT] from (select DOCTYPE, INVCNMBR from IVC10100 WUNION ALLselect DOCTYPE, INVCNMBR from IVC30101 H) Cgroup by DOCTYPE, INVCNMBRhaving COUNT(*) > 1
-- POP PO Duplicatesselect PONUMBER, COUNT(*) as [COUNT] from (select PONUMBER from POP10100 WUNION ALLselect PONUMBER from POP30100 H) Cgroup by PONUMBERhaving COUNT(*) > 1
-- POP Receivingss Duplicatesselect POPRCTNM, COUNT(*) as [COUNT] from (select POPRCTNM from POP10300 WUNION ALLselect POPRCTNM from POP30300 H) Cgroup by POPRCTNMhaving COUNT(*) > 1
-- RM Duplicatesselect RMDTYPAL, DOCNUMBR, COUNT(*) as [COUNT] from (select RMDTYPAL, RMDNUMWK as DOCNUMBR from RM10301 WUNION ALLselect RMDTYPAL, DOCNUMBR from RM10201 WUNION ALLselect RMDTYPAL, DOCNUMBR from RM20101 OUNION ALLselect RMDTYPAL, DOCNUMBR from RM30101 H) Cgroup by RMDTYPAL, DOCNUMBRhaving COUNT(*) > 1
-- PM Duplicatesselect DOCTYPE, VCHRNMBR, COUNT(*) as [COUNT] from (select DOCTYPE, VCHNUMWK as VCHRNMBR from PM10000 WUNION ALLselect DOCTYPE, VCHRNMBR from PM10300 PUNION ALLselect DOCTYPE, VCHRNMBR from PM10400 MUNION ALLselect DOCTYPE, VCHRNMBR from PM20000 OUNION ALLselect DOCTYPE, VCHRNMBR from PM30200 H) Cgroup by DOCTYPE, VCHRNMBRhaving COUNT(*) > 1
-- IV Duplicatesselect IVDOCTYP, DOCNUMBR, COUNT(*) as [COUNT] from (select IVDOCTYP, IVDOCNBR as DOCNUMBR from IV10000 WUNION ALLselect IVDOCTYP, DOCNUMBR from IV30200 H) Cgroup by IVDOCTYP, DOCNUMBRhaving COUNT(*) > 1
-- GL Duplicatesselect 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.JRNENTRYUNION ALLselect JRNENTRY, RCTRXSEQ, SEQNUMBR, ACTINDX, TRXDATE, CRDTAMNT, DEBITAMT, OPENYEAR as [YEAR] from GL20000 OUNION ALLselect JRNENTRY, RCTRXSEQ, SEQNUMBR, ACTINDX, TRXDATE, CRDTAMNT, DEBITAMT, HSTYEAR as [YEAR] from GL30000 H) Cgroup 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
Posting from the Dynamics GP Blogster
http://dynamicsgpblogster.blogspot.com/2008/12/sql-mania-series-at-developing-for.html
Posting from Vaidy Mohan's Blog
http://www.vaidy-dyngp.com/2008/12/davids-sql-series-identifying-duplicate.html
I just wanted to take a second and highlight again David Musgrave's very useful SQL Scripts Series
As always an awesome addition to my bag of tricks. David you rock!
By David Musgrave http://blogs.msdn.com/developingfordynamicsgp/archive/2008/12/05/identifying-duplicate-transactions.aspx
Based on the success of the "Resolving Security Issues in Dynamics GP" located here, Microsoft
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.
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.
Many of inquiry windows in Microsoft Dynamics GP have been optimized to leverage SQL Server to increase
I found it very useful, specially in fixing those transactions with posting interruption problems.
This is very useful for us David...Thanx a lot :)
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.
Kristen
Sounds like you might have a related but different issue.
You might want to ask on the forums or log a support case.
Posting by Mark Polino at DynamicAccounting.net
msdynamicsgp.blogspot.com/.../dynamics-gp-land-finding-duplicate-gl.html
PLEASE READ BEFORE POSTING
Please only post comments relating to the topic of this page.
If you wish to ask a technical question, please use the links in the links section (scroll down, on right hand side) to ask on the Newsgroups or Forums. If you ask on the Newsgroups or Forums, others in the community can respond and the answers are available for everyone in the future.