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
)
GO
INSERT INTO #POCHECK
(PONUMBER,POPRCTNM,CHCKDGIT,DCSTATUS)
--VALUES
(SELECT PONUMBER,'',1,1 FROM POP10100)
GO
INSERT INTO #POCHECK
(PONUMBER,POPRCTNM,CHCKDGIT,DCSTATUS)
--VALUES
(SELECT PONUMBER,'',1,3 FROM POP30100)
GO
INSERT INTO #POCHECK
(PONUMBER,POPRCTNM,CHCKDGIT,DCSTATUS)
--VALUES
(SELECT '',POPRCTNM,1,1 FROM POP10300)
GO
INSERT INTO #POCHECK
(PONUMBER,POPRCTNM,CHCKDGIT,DCSTATUS)
--VALUES
(SELECT '',POPRCTNM,1,3 FROM POP30300)
GO
SELECT
PONUMBER
,POPRCTNM
,SUM(CHCKDGIT) AS DCCOUNT
FROM
#POCHECK
GROUP BY
PONUMBER,POPRCTNM
HAVING
SUM(CHCKDGIT) > 1
GO
DROP TABLE #POCHECK
GO
After we used the script to identify the corrupt orders, it was a case of going through the returned records and correcting errors.