SELECT d.uco_code as assignmentstatuscode,
       d.uco_desc as assignmentstatusdesc
  FROM r5auth a,
       r5ucodes d,
       r5entities e
 WHERE ( (a.aut_user = <parameter.r5user> AND
          a.aut_group = '*' AND
          a.aut_status = <parameter.oldStatus> AND
          a.aut_statnew <> '*' AND
          d.uco_code = a.aut_statnew) OR
         (a.aut_user = <parameter.r5user> AND
          a.aut_group = '*' AND
          a.aut_status = '*' AND
          a.aut_statnew <> '*' AND
          d.uco_code = a.aut_statnew AND
          NOT EXISTS (
                  SELECT NULL
                    FROM r5auth x
                   WHERE x.aut_user = a.aut_user AND
                         x.aut_group = a.aut_group AND
                         x.aut_status = <parameter.oldStatus> AND
                         x.aut_statnew = a.aut_statnew AND
                         x.aut_rentity = a.aut_rentity AND
                         x.aut_type = '-'
              )
         ) OR
         (a.aut_user = <parameter.r5user> AND
          a.aut_group = '*' AND
          a.aut_status = <parameter.oldStatus> AND
          a.aut_statnew = '*' AND
          NOT EXISTS (
                  SELECT NULL
                    FROM r5auth x
                   WHERE x.aut_user = a.aut_user AND
                         x.aut_group = a.aut_group AND
                         x.aut_status = a.aut_status AND
                         x.aut_statnew = d.uco_code AND
                         x.aut_rentity = a.aut_rentity AND
                         x.aut_type = '-'
              )
         ) OR
         (a.aut_group = <parameter.userOrgGroup> AND
          a.aut_user = '*' AND
          NOT EXISTS (
                  SELECT NULL
                    FROM r5auth x
                   WHERE x.aut_user = <parameter.r5user> AND
                         x.aut_group = '*' AND
                         (x.aut_status = '*' OR
                          x.aut_status = <parameter.oldStatus>) AND
                         (x.aut_statnew = a.aut_statnew OR
                          x.aut_statnew = '*') AND
                         x.aut_rentity = a.aut_rentity AND
                         x.aut_type = '-'
              )
AND
          (a.aut_status = '*' OR
           a.aut_status = <parameter.oldStatus>) AND
          (d.uco_code = a.aut_statnew OR
           a.aut_statnew = '*') ) ) AND
       a.aut_rentity = 'ACTA' AND
       a.aut_type = '+' AND
       a.aut_statnew <> <parameter.oldStatus> AND
       e.ent_rentity = a.aut_rentity AND
       d.uco_rentity = 'AAST'
UNION
SELECT dd.uco_code,
       dd.uco_desc
  FROM r5ucodes dd,
       r5entities ee
 WHERE ee.ent_rentity = 'ACTA' AND
       uco_rentity = 'AAST' AND
       dd.uco_code = <parameter.oldStatus>
