-- 把t_OutByMachineDetail中V_BarCode重复并且IsDeleted为0的日期为Min的一条更改为IsDeleted为0
-- Powered By:记得忘记
UPDATE t_OutByMachineDetail
SET IsDeleted = 1
WHERE PID IN (
SELECT PID FROM t_OutByMachineDetail T1 RIGHT JOIN
(
select Min(D_Date) as D_MinDate,V_BarCode as BarCode from t_OutByMachineDetail where v_BarCode in
(select V_BarCode from t_OutByMachineDetail
where IsDeleted = 0
group by V_BarCode
having count(*) > 1)
group by V_BarCode
) T2
on T1.D_Date = T2.D_MinDate and T1.V_BarCode = T2.BarCode
WHERE T1.V_BarCode = T2.BarCode
and T1.IsChecked = 0
)
-- Powered By:记得忘记
UPDATE t_OutByMachineDetail
SET IsDeleted = 1
WHERE PID IN (
SELECT PID FROM t_OutByMachineDetail T1 RIGHT JOIN
(
select Min(D_Date) as D_MinDate,V_BarCode as BarCode from t_OutByMachineDetail where v_BarCode in
(select V_BarCode from t_OutByMachineDetail
where IsDeleted = 0
group by V_BarCode
having count(*) > 1)
group by V_BarCode
) T2
on T1.D_Date = T2.D_MinDate and T1.V_BarCode = T2.BarCode
WHERE T1.V_BarCode = T2.BarCode
and T1.IsChecked = 0
)