I have a MySQL Command and it looks like this
UPDATE Variance as VAR INNER JOIN receiving as REV ON (VAR.ItemCode = REV.ItemCode)
SET VAR.Receiving = REV.QtyPack * REV.PCS + REV.QtyStan;
I think you can just add the conditions directly into the query:
UPDATE Variance VAR INNER JOIN receiving REV ON VAR.ItemCode = REV.ItemCode SET VAR.Receiving = COALESCE(REV.QtyPack * REV.PCS + REV.QtyStan, 0) WHERE rev.Status = 'Posted' AND rev.date between $date1 and $date2;
NULL values to
0, which is part of the third condition.