I had a client report a problem with a couple of purchase orders which were showing in the PO Entry window, but which they could not open. While looking into the problem we found three things:
- The problem was down to corruption where the PO was on both the work and open tables;
- There was more than just two POs;
- The problem also affected receipts.
Rather than trying to identify the problems manually, I wrote a SQL script which would identify all POs and Receipts which were on both the Work and Open tables:
CREATE TABLE #POCHECK(
PONUMBER VARCHAR(20),POPRCTNM VARCHAR(20),CHCKDGIT INT,DCSTATUS INT)GOINSERT INTO #POCHECK(PONUMBER,POPRCTNM,CHCKDGIT,DCSTATUS)--VALUES(SELECT PONUMBER,'',1,1 FROM POP10100)GOINSERT INTO #POCHECK(PONUMBER,POPRCTNM,CHCKDGIT,DCSTATUS)--VALUES(SELECT PONUMBER,'',1,3 FROM POP30100)GOINSERT INTO #POCHECK(PONUMBER,POPRCTNM,CHCKDGIT,DCSTATUS)--VALUES(SELECT'',POPRCTNM,1,1 FROM POP10300)GOINSERT INTO #POCHECK(PONUMBER,POPRCTNM,CHCKDGIT,DCSTATUS)--VALUES(SELECT'',POPRCTNM,1,3 FROM POP30300)GOSELECT
PONUMBER,POPRCTNM,SUM(CHCKDGIT) AS DCCOUNTFROM
#POCHECKGROUP BY
PONUMBER,POPRCTNMHAVINGSUM(CHCKDGIT)> 1GODROP TABLE #POCHECKGO
After we used the script to identify the corrupt orders, it was a case of going through the returned records and correcting errors.