INSERT AfTER LEFT JOIN creates duplicate records
Posted by:
Brad Liu
Date: September 19, 2016 03:49PM
Below is the stored procedure running at work hours every day. The purpose is to add new and update records from SBT to so_detail.
INSERT INTO so_detail
(so_num, cust_num, part_num, descrip, disc, cost, price, qtyord, qtyshp, extprice, ord_date, req_date, dealer_type, part_cls, location, sostat, discls, wh_id)
SELECT s.sono, s.custno, s.item, s.descrip, s.disc, s.cost, s.price, s.qtyord, s.qtyshp, s.extprice, CONCAT(s.ordate, ' ', time(now())), CONCAT(s.rqdate, ' ', time(now())),
s.terr, s.class, s.seq, s.sostat, s.disclass, whID
FROM SBT.SOTRAN s
LEFT JOIN so_detail d ON s.sono = d.so_num AND s.item = d.part_num
WHERE d.so_num IS NULL;
Almost every one month, there is duplicated record (exactly the same for two lines of records ) in so_detail created.
Has no clue where these duplicates come from.
There is no place to insert screenshot? :)
Thank You!
Brad