-- ABS-70817 / ABS-81437
INSERT INTO CONTRACTEMBTEMPLINECUST
  (CONTRACTEMBTEMPLINE_ID, EMBLEMTEMPLATELINE_ID, SYSTEMUSER_ID, TIMESTAMP)
  SELECT CEL.CONTRACTEMBTEMPLINE_ID, ETL.EMBLEMTEMPLATELINE_ID, GETMINSYSTEMUSER(), SYSDATE
  FROM   CONTRACTEMBTEMPCUST CEC
  JOIN   CONTRACTEMBTEMPLINE CEL
  ON     CEL.CONTRACTEMBTEMP_ID = CEC.CONTRACTEMBTEMP_ID
  JOIN   EMBLEMTEMPLATELINE ETL
  ON     (ETL.EMBLEMTEMPLATE_ID = CEC.EMBLEMTEMPLATE_ID AND
         (ETL.PRODUCT_ID = CEL.PRODUCT_ID OR (ETL.PRODUCT_ID IS NULL AND CEL.PRODUCT_ID IS NULL)) AND
         ETL.SIZEDEFINITION_ID = CEL.SIZEDEFINITION_ID AND
         (ETL.TEXTCOLOR_ID = CEL.TEXTCOLOR_ID OR
         (ETL.TEXTCOLOR_ID IS NULL AND CEL.TEXTCOLOR_ID IS NULL)) AND
         (ETL.BORDERCOLOR_ID = CEL.BORDERCOLOR_ID OR
         (ETL.BORDERCOLOR_ID IS NULL AND CEL.BORDERCOLOR_ID IS NULL)) AND
         (ETL.BKGCOLOR_ID = CEL.BKGCOLOR_ID OR
         (ETL.BKGCOLOR_ID IS NULL AND CEL.BKGCOLOR_ID IS NULL)) AND ETL.FABRIC_ID = CEL.FABRIC_ID AND
         (ETL.PLACEMENT_ID = CEL.PLACEMENT_ID OR
         (ETL.PLACEMENT_ID IS NULL AND CEL.PLACEMENT_ID IS NULL)) AND
         (ETL.EMBLEMFONT_ID = CEL.EMBLEMFONT_ID OR
         (ETL.EMBLEMFONT_ID IS NULL AND CEL.EMBLEMFONT_ID IS NULL)) AND
         ETL.EMBLEMTYPE = CEL.EMBLEMTYPE)
  WHERE  NOT EXISTS (SELECT 1
          FROM   CONTRACTEMBTEMPLINECUST X
          WHERE  X.CONTRACTEMBTEMPLINE_ID = CEL.CONTRACTEMBTEMPLINE_ID
          AND    X.EMBLEMTEMPLATELINE_ID = ETL.EMBLEMTEMPLATELINE_ID);     
COMMIT;
