-- ABS-81504 SQ failed due to single row sub query error

delete from TEMPORARYDELIVERYSTOP TDS
 where TDS.TEMPORARYDELIVERYSTOP_ID not in
       (select max(TEMPORARYDELIVERYSTOP_ID)
          from TEMPORARYDELIVERYSTOP
         group by STANDARDDELIVERYLINE_ID,
                  TEMPORARYSTOPSTARTWEEK,
                  TEMPORARYSTOPENDWEEK,
                  TEMPSTOPRENTFORWEEK,
                  TEMPSTOPRENTFORYEARWEEK,
                  TEMPSTOPSTARTWEEKFORYEAR,
                  TEMPSTOPENDWEEKFORYEAR,
                  TEMPORARYSTOPSTARTYEAR,
                  TEMPORARYSTOPENDYEAR,
                  YEARLYSTOPRETURNWEEK,
                  TEMPSTOPRENTFORDATE,
                  STARTDATE,
                  ENDDATE);
commit;

alter table TEMPORARYDELIVERYSTOP add constraint XAK1TEMPORARYDELIVERYSTOP unique(STANDARDDELIVERYLINE_ID,
                                                                                  TEMPORARYSTOPSTARTWEEK,
                                                                                  TEMPORARYSTOPENDWEEK,
                                                                                  TEMPSTOPRENTFORWEEK,
                                                                                  TEMPSTOPRENTFORYEARWEEK,
                                                                                  TEMPSTOPSTARTWEEKFORYEAR,
                                                                                  TEMPSTOPENDWEEKFORYEAR,
                                                                                  TEMPORARYSTOPSTARTYEAR,
                                                                                  TEMPORARYSTOPENDYEAR,
                                                                                  YEARLYSTOPRETURNWEEK,
                                                                                  TEMPSTOPRENTFORDATE,
                                                                                  STARTDATE,
                                                                                  ENDDATE);

