-- ABS-97998/ ABS-98295
ALTER TABLE PRINTQUEUE ADD (CUSTOMEROWNED VARCHAR2(1) DEFAULT 'N' NOT NULL
                                          CONSTRAINT CHK_PRINTQUEUE_CUSTOMEROWNED CHECK (CUSTOMEROWNED IN ('Y', 'N')));

MERGE INTO PRINTQUEUE PQ
USING (SELECT UIL.UNIQUEITEM_LINK_ID, COALESCE(UI.CUSTOMEROWNED, RI.CUSTOMEROWNED,'N')  CUSTOMEROWNED
      FROM UNIQUEITEM_LINK UIL
      LEFT OUTER JOIN UNIQUEITEM UI ON UI.UNIQUEITEM_ID = UIL.UNIQUEITEM_ID
      LEFT OUTER JOIN RAGGEDITEM RI ON RI.RAGGEDITEM_ID = UIL.RAGGEDITEM_ID) X
ON (PQ.UNIQUEITEM_LINK_ID = X.UNIQUEITEM_LINK_ID AND PQ.INVOICEHEADER_ID IS NULL)
WHEN MATCHED THEN 
  UPDATE SET PQ.CUSTOMEROWNED = X.CUSTOMEROWNED;

COMMIT;