Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics GP (Archived)

The stored procedure create SQLTmpTable returned the following results: DBMS:2627

Posted on by 22,647

When looking at Transactions by Vendor, for only 1 vendor in the system, and having History and Open both selected on the Include line, we get an alert message: The stored procedure create SQLTmpTable returned the following results: DBMS:2627, Microsoft Dynamics GP:0

This only happens for 1 vendor and if I choose a different vendor - there are no error messages.

When I select only OPEN or only History - there is no error

This is recreated on all workstations for all users.

I have tried to run check-links on the Payables Management data

I have tried to find in SQL a common file - but I am not clear on where to look.

We believe this might be the result of a manual payment that was being recorded and while posting the user may have lost network connection.  There are no 'stray' batches

When we search the same vendor under Transaction by Document  we get no errors and we see both History and Open and more importantly we see the PMT and INV in the same list.

*This post is locked for comments

  • Joshua Page Profile Picture
    Joshua Page on at
    RE: The stored procedure create SQLTmpTable returned the following results: DBMS:2627

    Hi Bill!

    You are correct there can be dups between other tables (distribution tables, tax tables, apply tables), it's why I noted above to check the other tables :) Below is another script that will pull all the records from every table for the specific transaction.

    As always please be sure to have backups\ work in a test company before altering records on the backend if it's needed in your case.

    /*********************************************************************************
    ** All Payables info script.  Includes all Payables tables as well as GL, including:	
    
    **	Payables info:						
    **	PM00400 -	PM Key Master						
    **	PM10000 -	PM Transaction WORK					
    **	PM10100 -	PM Distribution WORK OPEN	
    **	PM10200 -	PM Apply To WORK OPEN
    **	PM10201 -	PM Payment Apply To Work			
    **	PM10300	-	PM Payment WORK				
    **	PM10400 -	PM Manual Payment WORK	
    **	PM10500 -	PM Tax Work	
    **	PM20000 -	PM Transaction OPEN			
    **	PM20100 -	PM Apply To OPEN OPEN Temporary		
    **	PM20200 -	PM Distribution OPEN OPEN Temporary	
    **	PM30200 -	PM Paid Transaction History		
    **	PM30300 -	PM Apply to History			
    **	PM30600 -	PM Distriubtion History			
    **	PM30700 -	PM Tax History	
    **	PM30800 -	PM Tax Invoices
    
    **	Payables Void Temporary Tables:
    **	PM10600 -	PM Distribution Void WORK Temporary		
    **	PM10801 -	PM Payment Stub Duplicate	
    **	PM10900 -	Void Payment WORK Temporary
    **	PM10901 -	PM Void Transaction WORK Temporary
    **	PM10902 -	PM Tax Void Work Temporary
    
    ** General Ledger:		
    **	GL10000	-	Transaction Work
    **	GL10001 -	Transaction Amounts Work
    **	GL20000 -	Year-to-Date Transaction Open
    **	GL30000 -	Account Transaction History
    
    **Multicurrency:
    **MC020103 -	Multicurrency Payables Transactions
    **MC020105 -	Multicurrency RM Revaluation Activity
    
    **Bank Reconcilation:
    **CM20200 -		CM Transaction
    
    Instructions:	
    				
    	Step 1. Replace 00000000000000447 with the document's Voucher/Payment Number for @VCHRNMBR. The Voucher/Payment Number can be seen from Inquiry> 
    	Purchasing> Transaction by Vendor. Click the Show details button to view the Voucher/Payment Number. 
    
    
    	Step 2. Enter the appropriate DOCTYPE Value for @DOCTYPE :
    	1=Invoice
    	2=Finance Charge
    	3=Miscellaneous Charge
    	4=Return
    	5=Credit Memo
    	6=Payment
     
    	Step 3. Select the appropriate company database and click Execute.
    
    GP VERSIONS: 10.0, 2010, 2013  
    
    REVISION HISTORY:
    
    Date          	Who             Comments
    ------------- 	--------------	------------------------------------------------
    10/08/2014		amelroe			Modified select statement in relation to printing data for PM20100 table to pull from PM20100 instead of PM10201
    								Modified select statement in relation to printing data for PM20200 table to pull from PM20200 instead of PM10100
    								Modified select statement in relation to printing data for PM30700 table to pull from PM30700 instead of PM30200
    				
    *********************************************************************************/
    
    ----------------------------------------------------------------------------------
    declare @VCHRNMBR char(20)
    declare @DOCTYPE smallint
    
    select @VCHRNMBR = '00000000000000447'
    select @DOCTYPE = '1'
    ----------------------------------------------------------------------------------
    
    /*Payables info*/
    
    print '=================================================================================='
    print 'Payables info'
    print '=================================================================================='
    print ''
    Begin
    
    Begin
    print 'PM00400 - PM Key Master'
    	select * from PM00400 where CNTRLNUM = @VCHRNMBR and DOCTYPE=@DOCTYPE
    End
    
    Begin
    print 'PM10000 - PM Transaction WORK'
    	select * from PM10000 where VCHNUMWK = @VCHRNMBR and DOCTYPE=@DOCTYPE
    End
    
    Begin
    	print 'PM10100 - PM Distribution WORK OPEN'
    	
    if @DOCTYPE <=5 (select * from PM10100 where VCHRNMBR = @VCHRNMBR and CNTRLTYP=0)
    if @DOCTYPE	 =6 (select * from PM10100 where VCHRNMBR = @VCHRNMBR and CNTRLTYP=1)
    	End 
    
    Begin 
    	print 'PM10200 - PM Apply To WORK OPEN'
    if @DOCTYPE <=3 (Select * from PM10200 where APTVCHNM=@VCHRNMBR)
    if @DOCTYPE >=4 (select * from PM10200 where VCHRNMBR=@VCHRNMBR)
    	End
    
    Begin 
    	print 'PM10201 - PM Payment Apply To Work'
    if @DOCTYPE <=3 (Select * from PM10201 where APTVCHNM=@VCHRNMBR)
    if @DOCTYPE  =6 (select * from PM10201 where PMNTNMBR = @VCHRNMBR)
    	End
    
    Begin 
    if @DOCTYPE = 6 
    	print 'PM10300 - PM Payment WORK'
    if @DOCTYPE = 6 (Select * from PM10300 where PMNTNMBR=@VCHRNMBR)
    	End
    
    Begin 
    if @DOCTYPE = 6 
    	print 'PM10400 - PM Manual Payment WORK'
    if @DOCTYPE = 6 (Select * from PM10400 where PMNTNMBR=@VCHRNMBR)
    	End
    
    Begin 
    	print 'PM10500 - PM Tax Work'
    	Select * from PM10500 where VCHRNMBR=@VCHRNMBR
    	End
    
    Begin
    print 'PM20000 - PM Transaction Open'
    	select * from PM20000 where VCHRNMBR = @VCHRNMBR and DOCTYPE=@DOCTYPE
    End
    
    Begin
    print 'PM20100 - PM Apply To OPEN OPEN Temporary'
    	if @DOCTYPE <=3 (Select * from PM20100 where APTVCHNM=@VCHRNMBR)      /*amelroe 10/08/2014*/
    	if @DOCTYPE >=4 (select * from PM20100 where VCHRNMBR = @VCHRNMBR)    /*amelroe 10/08/2014*/
    End
    
    Begin
    	print 'PM20200 - PM Distribution OPEN OPEN Temporary'
    	
    if @DOCTYPE <=5 (select * from PM20200 where APTVCHNM = @VCHRNMBR)     /*amelroe 10/08/2014*/
    if @DOCTYPE = 6 (select * from PM20200 where VCHRNMBR = @VCHRNMBR)     /*amelroe 10/08/2014*/
    	End 
    
    	Begin
    print 'PM30200 - PM Paid Transaction History'
    	select * from PM30200 where VCHRNMBR = @VCHRNMBR and DOCTYPE=@DOCTYPE
    End
    
    Begin
    print 'PM30300 - PM Apply To History'
    	if @DOCTYPE <=3 (Select * from PM30300 where APTVCHNM=@VCHRNMBR)
    	if @DOCTYPE >=4 (select * from PM30300 where VCHRNMBR = @VCHRNMBR)
    End
    
    Begin
    	print 'PM30600 - PM Distribution History'
    	
    if @DOCTYPE <=5 (select * from PM30600 where VCHRNMBR = @VCHRNMBR and CNTRLTYP=0)
    if @DOCTYPE = 6 (select * from PM30600 where VCHRNMBR = @VCHRNMBR and CNTRLTYP=1)
    End 
    
    Begin
    print 'PM30700 - PM Tax History'
    	select * from PM30700 where VCHRNMBR = @VCHRNMBR and DOCTYPE=@DOCTYPE     /*amelroe 10/08/2014*/
    End
    
    Begin
    print 'PM30800 - PM Tax Invoices'
    	select * from PM30800 where VCHRNMBR = @VCHRNMBR and DOCTYPE=@DOCTYPE
    End
    
    /*Payables Void Temporary Tables*/
    
    print '=================================================================================='
    print 'Payables Void Temporary Tables'
    print '=================================================================================='
    print ''
    
    Begin 
    	print 'PM10600 - PM Distribution Void WORK Temporary'
    if @DOCTYPE <=5 (select * from PM10600 where VCHRNMBR = @VCHRNMBR and CNTRLTYP=0)
    if @DOCTYPE = 6 (select * from PM10600 where VCHRNMBR = @VCHRNMBR and CNTRLTYP=1)
    	End 
    
    Begin 
    if @DOCTYPE = 6
    	print 'PM10801 - PM Payment Stub Duplicate'
    if @DOCTYPE = 6 (select * from PM10801 where PMNTNMBR = @VCHRNMBR)
    	End 
    
    Begin 
    	print 'PM10900 - Void Payment WORK Temporary'
    		select * from PM10900 where VCHRNMBR = @VCHRNMBR and DOCTYPE=@DOCTYPE
    	End 
    
    Begin 
    	print 'PM10901 - PM Void Transaction WORK Temporary'
    		select * from PM10901 where VCHRNMBR = @VCHRNMBR and DOCTYPE=@DOCTYPE
    	End 
    
    Begin 
    	print 'PM10902 - PM Tax Void Work Temporary'
    		select * from PM10902 where VCHRNMBR = @VCHRNMBR 
    	End 
    
    /*General Ledger*/
    print '=================================================================================='
    print 'GL info'
    print '=================================================================================='
    print ''
    
    Begin
    print 'GL10000 - Transaction Work'
    /*print '========'*/
    select * from GL10000  where  DTAControlNum= @VCHRNMBR AND DTATRXType=@DOCTYPE
    End
    
    Begin
    print 'GL10001 - Transaction Amounts Work'
    /*print '========'*/
    select * from GL10001 WHERE JRNENTRY IN (SELECT JRNENTRY FROM GL10000 WHERE DTAControlNum= @VCHRNMBR AND DTATRXType=@DOCTYPE)
    End
    Begin
    print 'GL20000 - Year-to-Date Transaction Open'
    /*print '========'*/
    select * from GL20000 where ORCTRNUM = @VCHRNMBR AND ORTRXTYP=@DOCTYPE
    End
    Begin
    print 'GL30000 - Account Transaction History'
    /*print '========'*/
    select * from GL30000 where ORCTRNUM = @VCHRNMBR AND ORTRXTYP=@DOCTYPE
    End
    End
    
    /*Multicurrency Info*/
    print '=================================================================================='
    print 'Multicurrency Info'
    print '=================================================================================='
    print ''
    
    Begin
    print 'MC020103 - Multicurrency Payables Transactions'
    /*print '========'*/
    
    select  * from MC020103 where VCHRNMBR=@VCHRNMBR and DOCTYPE=@DOCTYPE
    End
    
    Begin
    print 'MC020105 - Multicurrency RM Revaluation Activity'
    /*print '========'*/
    select * from MC020105 where VCHRNMBR=@VCHRNMBR and DOCTYPE=@DOCTYPE
    End
    
    /*Bank Reconcilation*/
    print '=================================================================================='
    print 'Bank Reconcilation'
    print '=================================================================================='
    print ''
    
    Begin
    print 'CM20200 - CM Transaction'
    /*print '========'*/
    select * from CM20200 where SRCDOCNUM=@VCHRNMBR and SRCDOCTYP=@DOCTYPE
    End
    
    
    


  • Bill Campbell Profile Picture
    Bill Campbell 22,647 on at
    RE: The stored procedure create SQLTmpTable returned the following results: DBMS:2627

    Thinking about this - would there not be duplicates in the other tables - or are you thinking that PM20000 and PM30200 might get stalled and there the balance hangs in the OPEN side and or gets over totally to HISTORY.

    I will check to see if there is anything hanging - but i am pretty sure we are good with the OPEN record removal.  

    I will update after additional testing.

  • Joshua Page Profile Picture
    Joshua Page on at
    RE: The stored procedure create SQLTmpTable returned the following results: DBMS:2627

    Hi Bill!

    Thank you for your update! I see you where able to find a duplicate with the script!

    Dups between PM20000 and PM30200 can be simple (like you noted it may be possible to just remove the record from the open tables). before removing the records however you will want to verify that all needed records made it to history.

    This includes tax information(if present), distributions, apply records, etc. Once you know which set (Open or history) is complete (if either set is complete) you'll know which one will need to be removed for the repair. Also note you will need to make sure GL was updated correctly as well. With dups between open and history this is usually okay though.

    If you have any questions you may want to open a support case on this one to verify which set of data is correct.

    Joshua

  • Suggested answer
    Bill Campbell Profile Picture
    Bill Campbell 22,647 on at
    RE: The stored procedure create SQLTmpTable returned the following results: DBMS:2627

    I have determined the issue to be thus.

    VCHRNMBR 564
    DocNumbr 42274
    DocAmount 426.49

    Exists in both the PM20000 and the PM30200

    From all the scripts I have been able to put together and from my understanding of the way the system 'hangs' I should only have to delete the record from the PM20000 (Open) and it will then remove the duplicate error as there will no longer be a duplicate in both Open and History.

    I know we want the record in History as it is one of the invoice that was being paid by the manual check.

    Any one to confirm?

  • Bill Campbell Profile Picture
    Bill Campbell 22,647 on at
    RE: The stored procedure create SQLTmpTable returned the following results: DBMS:2627

    Just to be clear, I run this "all" at one time and it tells me where and what the duplicates are in the various PM tables?

  • Suggested answer
    Joshua Page Profile Picture
    Joshua Page on at
    RE: The stored procedure create SQLTmpTable returned the following results: DBMS:2627

    Hi Bill! It sounds like you might have a duplicate in the tables. (probably between open and history) below is a script that can be used to check for duplicates. If it returns results you may want to consider opening up a support case to determine the best course of action for the repair. You would run the below script against the company DB in SQL Server Management Studio.

    /*
    ** Procedure Name:  PM_Find_Dups.sql
    **
    ** Description:
    **
    **	Looks for many different kinds of duplicates many that may cause PM00400 (PMKeys Table)
    **	to error out.  Once Duplicates are found they will need to be dealt with on a one by 
    **	one basis.  Run in TEXT Mode (CTRL - T)
    **
    ** Database:	Company
    **
    ** Versions:	7.00, 6.00, 5.50, 5.51, 5.00
    ** SQL Version:	2000, 7.0
    ** 
    ** Tables:
    **
    ** 	SQL Table			Access Method
    ** 	---------------------		-------------
    **	PM10000				Read
    **	PM10100				Read
    ** 	PM10300				Read
    **	PM10400				Read
    **	PM20000				Read
    **	PM30200				Read
    **	PM30600				Read
    **	Various Temp Tables		##Temp**
    **               
    ** Revision History:
    **
    **       Date           Who			Comments
    **       ------------   --------------------	------------------------------------------
    **	??/??/????	???			Creation Date
    **	02/15/2003	Chad Aberle		Added Checks for PKPM00400 possibility
    **	04/22/2003	Chad Aberle		Fixed inner join scripting checks
    **	06/26/2003	Chad Aberle		Added PM10100 and PM30600 Dup Check
    **	7/11/2003	Chad Aberle		Use Exists function to remove subquery error
    **	2/13/2004	Brent Everson		Issue with ##Temp4 script, rewrote with inner join
    **
    ******************************************************************************************
    */
    
    /* First create a temp table to hold the PM Trans Work (PM10000) duplicates that
    ** are also found in the PM Trans Open (PM20000)*/
    SET NOCOUNT ON
    
    DECLARE @ERR int 
    Set @ERR=0 
     
    CREATE TABLE dbo.##Temp1 (
     VCHNUMWK char (17) NOT NULL ,
     VENDORID char (15) NOT NULL ,
     DOCTYPE smallint NOT NULL )
    
    /* Next insert into the ##Temp1 the documents that are duplicates in the PM10000 
    ** and the PM20000*/
    
    INSERT ##Temp1
    (W.VCHNUMWK,W.VENDORID,W.DOCTYPE)
    SELECT O.VCHRNMBR,O.VENDORID,O.DOCTYPE
    FROM PM10000 W, PM20000 O
    WHERE W.VCHNUMWK IN (SELECT O.VCHRNMBR FROM PM20000)
    AND W.DOCTYPE=O.DOCTYPE
    
    /* Create a temp table to hold the PM Payment Work (PM10300) duplicates that
    ** are also found in the PM Trans Open (PM20000)*/
    
    CREATE TABLE dbo.##Temp2 (
     VCHNUMWK char (17) NOT NULL ,
     VENDORID char (15) NOT NULL ,
     DOCTYPE smallint NOT NULL )
    
    /* Next insert into the ##Temp2 the documents that are duplicates in the PM10300
    ** and the PM20000*/
    
    INSERT ##Temp2
    (W.VCHNUMWK,W.VENDORID,W.DOCTYPE)
    SELECT O.VCHRNMBR,O.VENDORID,O.DOCTYPE
    FROM PM10300 W, PM20000 O
    WHERE W.PMNTNMBR IN (SELECT O.VCHRNMBR FROM PM20000)
    AND W.DOCTYPE=O.DOCTYPE
    
    /* Create a temp table that will hold duplicates found in the PM10000 and the 
    ** PM30200 tables*/
    
    CREATE TABLE dbo.##Temp3 (
     VCHNUMWK char (17) NOT NULL ,
     VENDORID char (15) NOT NULL ,
     DOCTYPE smallint NOT NULL )
    
    /* Next insert all the duplicates that are found in the PM10000 and the PM30200
    ** tables*/
    
    INSERT ##Temp3
    (W.VCHNUMWK,W.VENDORID,W.DOCTYPE)
    SELECT O.VCHRNMBR,O.VENDORID,O.DOCTYPE
    FROM PM10000 W, PM30200 O
    WHERE W.VCHNUMWK IN (SELECT O.VCHRNMBR FROM PM30200)
    AND W.DOCTYPE=O.DOCTYPE
    
    /* Create a temp table that will hold duplicates found in the PM10300 and the 
    ** PM30200 tables*/
    
    CREATE TABLE dbo.##Temp4 (
     VCHNUMWK char (21) NOT NULL ,
     VENDORID char (15) NOT NULL ,
     DOCTYPE smallint NOT NULL )
    
    /* Next insert all the duplicates that are found in the PM10300 and the PM30200
    ** tables*/
    
    INSERT ##Temp4
    (W.VCHNUMWK,W.VENDORID,W.DOCTYPE)
    SELECT O.VCHRNMBR,O.VENDORID,O.DOCTYPE
    FROM PM10300 W inner join PM30200 O
    ON W.DOCTYPE=O.DOCTYPE and W.VCHRNMBR = O.VCHRNMBR
    
    /* Create a temp table that will hold duplicates found in the PM20000 and the 
    ** PM30200*/
    
    CREATE TABLE dbo.##Temp5 (
     VCHNUMWK char (17) NOT NULL ,
     VENDORID char (15) NOT NULL ,
     DOCTYPE smallint NOT NULL )
    
    /* Next insert all the duplicates that are found in the PM20000 and the PM30200
    ** tables*/
    
    INSERT ##Temp5
    (W.VCHNUMWK,W.VENDORID,W.DOCTYPE)
    SELECT O.VCHRNMBR,O.VENDORID,O.DOCTYPE
    FROM PM20000 W, PM30200 O
    WHERE W.VCHRNMBR IN (SELECT O.VCHRNMBR FROM PM30200)
    AND W.DOCTYPE=O.DOCTYPE
    
    
    
    /* Now select the information from these tables*/
    if (select count(*) from ##Temp1) > 0 
    begin
    	set @ERR=1 
    	print 'Duplicates in the PM10000 Work Table and the PM20000 Open Table'
    	select * from ##Temp1
    end
    --******************
    if (select count(*) from ##Temp2) > 0 
    begin
    	set @ERR=1
    	print 'Duplicates in the PM10300 Payment Work Table and the PM20000 Open Table'
    	select * from ##Temp2
    end
    --******************
    if (select count(*) from ##Temp3) > 0 
    begin
    	set @ERR=1
    	print 'Duplicates in the PM10000 Work Table and the PM30200 History Table'
    	select * from ##Temp3
    end
    --******************
    if (select count(*) from ##Temp4) > 0 
    begin
    	set @ERR=1
    	print 'Duplicates in the PM10300 Payment Work Table and the PM30200 History Table'
    	select * from ##Temp4
    end
    --******************
    if (select count(*) from ##Temp1) > 0 
    begin
    	set @ERR=1
    	print 'Duplicates in the PM20000 Open Table and the PM30200 History Table'
    	select * from ##Temp5
    end
    --******************
    
    
    
    --Duplicates among tables causing Primary Key Violation on PM00400
    --******************
    select a.VCHRNMBR, a.CNTRLTYP into ##Temp6 from PM10000 a inner join PM20000 b
    on a.VCHRNMBR=b.VCHRNMBR and a.CNTRLTYP=b.CNTRLTYP
    
    if (select count(*) from ##Temp6) > 0 
    begin
    	set @ERR=1
    	print 'Duplicate Voucher Number and Control Type combination in the PM10000 Work Table and the PM20000 Open Table'
    	select * from ##Temp6
    end
    --******************
    select a.VCHRNMBR, a.CNTRLTYP into ##Temp7 from PM10300 a inner join PM20000 b
    	on a.VCHRNMBR=b.VCHRNMBR and a.CNTRLTYP=b.CNTRLTYP
    
    if (select count(*) from ##Temp7) > 0 
    begin
    	set @ERR=1
    	print 'Duplicate Voucher Number and Control Type combination in the PM10300 PMT Work Table and the PM20000 Open Table'
    	select * from ##Temp7
    end
    --******************
    select a.VCHRNMBR, a.CNTRLTYP into ##Temp8 from PM10400 a inner join PM20000 b
    	on a.VCHRNMBR=b.VCHRNMBR and a.CNTRLTYP=b.CNTRLTYP
    
    if (select count(*) from ##Temp8) > 0 
    begin
    	set @ERR=1
    	print 'Duplicate Voucher Number and Control Type combination in the PM10400 Manual PMT Work Table and the PM20000 Open Table'
    	select * from ##Temp8
    end
    --******************
    select a.VCHRNMBR, a.CNTRLTYP into ##Temp9 from PM20000 a inner join PM30200 b
    	on a.VCHRNMBR=b.VCHRNMBR and a.CNTRLTYP=b.CNTRLTYP
    
    if (select count(*) from ##Temp9) > 0 
    begin
    	set @ERR=1
    	print 'Duplicate Voucher Number and Control Type combination in the PM20000 Open Table and the PM30200 History Table'
    	select * from ##Temp9
    end
    --******************
    select a.VCHRNMBR, a.CNTRLTYP into ##Temp10 from PM10000 a inner join PM30200 b
    	on a.VCHRNMBR=b.VCHRNMBR and a.CNTRLTYP=b.CNTRLTYP
    
    if (select count(*) from ##Temp10) > 0 
    begin
    	set @ERR=1
    	print 'Duplicate Voucher Number and Control Type combination in the PM10000 Work Table and the PM30200 History Table'
    	select * from ##Temp10
    end
    --******************
    select a.VCHRNMBR, a.CNTRLTYP into ##Temp11 from PM10300 a inner join PM30200 b
    on a.VCHRNMBR=b.VCHRNMBR and a.CNTRLTYP=b.CNTRLTYP
    
    if (select count(*) from ##Temp11) > 0 
    begin
    	set @ERR=1
    	print 'Duplicate Voucher Number and Control Type combination in the PM10300 PMT Work Table and the PM30200 History Table'
    	select * from ##Temp11
    end
    --******************
    select a.VCHRNMBR, a.CNTRLTYP into ##Temp12 from PM10400 a inner join PM30200 b
    	on a.VCHRNMBR=b.VCHRNMBR and a.CNTRLTYP=b.CNTRLTYP
    
    if (select count(*) from ##Temp12) > 0 
    begin
    	set @ERR=1
    	print 'Duplicate Voucher Number and Control Type combination in the PM10400 Manual PMT Work Table and the PM30200 History Table'
    	select * from ##Temp12
    end
    --******************
    select a.VCHRNMBR, a.CNTRLTYP into ##Temp13 from PM10300 a inner join PM10400 b
    	on a.VCHRNMBR=b.VCHRNMBR and a.CNTRLTYP=b.CNTRLTYP
    
    if (select count(*) from ##Temp13) > 0 
    begin
    	set @ERR=1
    	print 'Duplicate Voucher Number and Control Type combination in the PM10300 PMT Work Table and the PM10400 Manual PMT Work Table'
    	select * from ##Temp13
    end
    --******************
    select a.VCHRNMBR, a.CNTRLTYP, a.APTVCHNM, a.SPCLDIST, a.DSTSQNUM, c.DOCNUMBR into ##Temp14 from PM10100 a inner join PM30600 b
    	on a.VCHRNMBR=b.VCHRNMBR and a.CNTRLTYP=b.CNTRLTYP and a.APTVCHNM=b.APTVCHNM
    	and a.SPCLDIST=b.SPCLDIST and a.DSTSQNUM=b.DSTSQNUM
    	left outer join PM00400 c on a.VCHRNMBR = c.CNTRLNUM and a.CNTRLTYP = c.CNTRLTYP
    
    if (select count(*) from ##Temp14) > 0 
    begin
    	set @ERR=1
    	print 'Duplicate Distribution Records in the PM10100 Work Table and the PM30600 History Table'
    	select * from ##Temp14
    end
    --******************
    select VCHRNMBR, CNTRLTYP into ##Temp15 from PM10100
    	where VCHRNMBR not in (select VCHRNMBR from PM10000) and
    	VCHRNMBR not in (select VCHRNMBR from PM20000 where CNTRLTYP = 0)
    	and CNTRLTYP = 0
    
    if (select count(*) from ##Temp15) > 0 
    begin
    	set @ERR=1
    	print 'Distribution Records in the PM10100 but not in PM10000 or PM20000 for Invoices, Misc, Finance Docs, CM, & Returns'
    	select * from ##Temp15
    end
    --******************
    
    select VCHRNMBR into ##Temp16 from PM10100 
    	where VCHRNMBR not in (select VCHRNMBR from PM10300) and
    	VCHRNMBR not in (select VCHRNMBR from PM10400) and
    	VCHRNMBR not in (select VCHRNMBR from PM20000 where CNTRLTYP = 1)
    	and CNTRLTYP = 1
    
    if (select count(*) from ##Temp16) > 0 
    begin
    	set @ERR=1
    	print 'Distribution Records in the PM10100 but not in PM10300, PM10400 or PM20000 for PMT'
    	select * from ##Temp16
    end
    --******************
    
    
    --Testing Within Tables Themselves (Possibly from Migration Problems)
    if exists (select count(*) from PM10000 group by VCHRNMBR,CNTRLTYP having count(*) > 1)
    begin
    	set @ERR=1
    	print 'Duplicate Voucher Number and Control Type combination in the PM10000 Work Table'
    	select VCHRNMBR,CNTRLTYP from PM10000 group by VCHRNMBR,CNTRLTYP having count(*) > 1
    end
    --******************
    if exists (select count(*) from PM10300 group by PMNTNMBR,CNTRLTYP having count(*) > 1)
    begin
    	set @ERR=1
    	print 'Duplicate Voucher Number and Control Type combination in the PM10300 PMT Work Table'
    	select PMNTNMBR,CNTRLTYP from PM10300 group by PMNTNMBR,CNTRLTYP having count(*) > 1
    end
    --******************
    if exists (select count(*) from PM10400 group by VCHRNMBR,CNTRLTYP having count(*) > 1)
    begin
    	set @ERR=1
    	print 'Duplicate Voucher Number and Control Type combination in the PM10400 Manual PMT Work Table'
    	select VCHRNMBR,CNTRLTYP from PM10400 group by VCHRNMBR,CNTRLTYP having count(*) > 1
    end
    --******************
    if exists (select count(*) from PM20000 group by VCHRNMBR,CNTRLTYP having count(*) > 1)
    begin
    	set @ERR=1
    	print 'Duplicate Voucher Number and Control Type combination in the PM20000 Open Table'
    	select VCHRNMBR,CNTRLTYP from PM20000 group by VCHRNMBR,CNTRLTYP having count(*) > 1
    end
    --******************
    if exists (select count(*) from PM30200 group by VCHRNMBR,CNTRLTYP having count(*) > 1)
    begin
    	set @ERR=1
    	print 'Duplicate Voucher Number and Control Type combination in the PM30200 History Table'
    	select VCHRNMBR,CNTRLTYP from PM30200 group by VCHRNMBR,CNTRLTYP having count(*) > 1
    end
    --******************
    
    
    drop table ##Temp1
    drop table ##Temp2
    drop table ##Temp3
    drop table ##Temp4
    drop table ##Temp5
    drop table ##Temp6
    drop table ##Temp7
    drop table ##Temp8
    drop table ##Temp9
    drop table ##Temp10
    drop table ##Temp11
    drop table ##Temp12
    drop table ##Temp13
    drop table ##Temp14
    drop table ##Temp15
    drop table ##Temp16
    
    --******************
    if @ERR=0
    	begin
    	print 'Completed successfully; no duplicates found'
    	end
    else
    	begin
    	print 'Completed successfully; Warning, duplicates found'
    	end
    
    
    
    
    
    
    


Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans