
/*------ ATD 480006 ------*/
DELETE R
FROM RelacionaPedidoCompraOrcamento R
WHERE EXISTS (
SELECT 1
FROM RelacionaPedidoCompraOrcamento R2
WHERE R2.itemvenda = R.itemvenda
AND R2.item > R.item
);

DELETE R
FROM RelacionaPedidoCompraOrcamento R
WHERE NOT EXISTS (
SELECT 1
FROM ItemCliCad I
WHERE I.Item = R.itemvenda
);
