SELECT   DISTINCT STVTERM.STVTERM_CODE AS "TERM CODE",
                  SORHSCH.SORHSCH_PIDM AS PIDM,
                  SPRIDEN.SPRIDEN_ID AS "BANNER ID",
                  SPRIDEN.SPRIDEN_LAST_NAME AS "LAST NAME",
                  SPRIDEN.SPRIDEN_FIRST_NAME AS "FIRST NAME",
                  SPRIDEN.SPRIDEN_MI AS MIDDLE,
                  SPBPERS.SPBPERS_BIRTH_DATE AS DOB,
                  to_char(spbpers.spbpers_birth_date, 'ddMonyyyy') AS "TEXT DOB",
                  SORHSCH.SORHSCH_SBGI_CODE AS "SBGI CODE",
                  STVSBGI.STVSBGI_DESC AS "SCHOOL NAME",
                  SORHSCH.SORHSCH_GRADUATION_DATE AS "GRAD DATE",
                  to_char(sorhsch.sorhsch_graduation_date, 'ddMonyyyy') AS "TEXT GRAD DATE"
FROM     SATURN.STVTERM STVTERM
         CROSS JOIN (((SATURN.SORHSCH SORHSCH
                       INNER JOIN (SELECT   SORHSCH.SORHSCH_PIDM AS PIDM, MAX(SORHSCH.SORHSCH_ACTIVITY_DATE) AS PICK_DATE
                                   FROM     SATURN.SORHSCH SORHSCH
                                   GROUP BY SORHSCH.SORHSCH_PIDM) Subquery
                         ON (SORHSCH.SORHSCH_PIDM = Subquery.PIDM) AND (SORHSCH.SORHSCH_ACTIVITY_DATE = Subquery.PICK_DATE))
                      LEFT OUTER JOIN SATURN.STVSBGI STVSBGI ON (SORHSCH.SORHSCH_SBGI_CODE = STVSBGI.STVSBGI_CODE))
                     LEFT OUTER JOIN SATURN.SPRIDEN SPRIDEN ON (SORHSCH.SORHSCH_PIDM = SPRIDEN.SPRIDEN_PIDM))
         LEFT OUTER JOIN SATURN.SPBPERS SPBPERS
           ON (SORHSCH.SORHSCH_PIDM = SPBPERS.SPBPERS_PIDM)
WHERE    (STVTERM.STVTERM_CODE LIKE :STVTERM_CODE) AND (SPRIDEN.SPRIDEN_ID LIKE :SPRIDEN_ID) AND (UPPER(SPRIDEN.SPRIDEN_LAST_NAME)
         LIKE
           UPPER                                                                                  ( :SPRIDEN_LAST_NAME)) AND (
         SORHSCH.SORHSCH_SBGI_CODE LIKE
           :SORHSCH_SBGI_CODE) AND (UPPER(STVSBGI.STVSBGI_DESC) LIKE UPPER( :STVSBGI_DESC)) AND (SPRIDEN.SPRIDEN_CHANGE_IND IS NULL
         ) AND SORHSCH.SORHSCH_GRADUATION_DATE > STVTERM.STVTERM_START_DATE AND SPRIDEN.SPRIDEN_ID NOT LIKE 'BAD%'
ORDER BY "LAST NAME" ASC, "FIRST NAME" ASC, MIDDLE ASC