--Order 20015415


ALTER TABLE STOCKQUANTITY
	ADD (STOCKDIFFERENCE NUMBER  DEFAULT 0 NULL);

ALTER TABLE BKP_STOCKQUANTITY
	ADD (STOCKDIFFERENCE NUMBER  DEFAULT 0 NULL);

COMMENT ON COLUMN STOCKQUANTITY.STOCKDIFFERENCE
  IS 'Diff between Qty Counted  and total Qty on stock (QtyUnique + QtyUniqueWithModifications + QtyNonUnique)';

update stockquantity sq
set sq.stockdifference = sq.qtycounted - sq.qtyunique - sq.qtyuniquewithmodifications - sq.qtynonunique
where sq.qtycounted is not null and sq.datecounted is not null
and trunc(sq.timestamp) <= trunc(sq.datecounted);

commit;