WITH DUP_BARCODE (ITEMBARCODE, DUPCOUNT) AS
(SELECT ITEMBARCODE, COUNT(RECID) AS DUPCOUNT
FROM INVENTITEMBARCODE
GROUP BY ITEMBARCODE
HAVING COUNT(RECID) > 1)
DELETE FROM INVENTITEMBARCODE
FROM INVENTITEMBARCODE AS I1
JOIN DUP_BARCODE ON I1.ITEMBARCODE = DUP_BARCODE.ITEMBARCODE
WHERE I1.RECID != (SELECT TOP 1 RECID FROM INVENTITEMBARCODE AS I2 WHERE I2.ITEMBARCODE = I1.ITEMBARCODE ORDER BY I1.CREATEDDATETIME ASC)
No comments:
Post a Comment