DROP VIEW `stan_zuw_so`;                   
CREATE VIEW stan_zuw_so 
AS 
SELECT f.saaid, a.wagsid, b.uid, b.vorname, b.nachname, b.hs, b.poplz, b.poOrt, b.poStrasse, b.AG, b.Jahrgang, d.standort,e.bezeichnung, f.beginn, f.ende, f.dst_id
  FROM stan_ag_standort_wunsch a, stud b, stan_ag_standort c,stan_standort d, stan_vertiefungsbereich e, stan_antrag f
 WHERE a.uid = b.uid
   AND c.agsid = a.wagsid
   AND c.sid = d.sid
   AND c.vbid = e.vbid
   AND a.saaid = f.saaid
   AND a.prio = 0
   AND f.status = (SELECT max(t2.status)
                     FROM stan_antrag t2 
                    WHERE f.aendid = t2.aendid
                      AND t2.status != '2')
   AND a.saaid not in (SELECT t1.saaid AS saaid from stan_printqueue_antrag t1
                        WHERE t1.saaid = a.saaid
                          AND t1.zuweisung =  'SOZ'
                          AND t1.printed_obj = a.wagsid)
   AND (f.zuweisung NOT IN ('E', 'EZ')
        OR f.zuweisung IS NULL
       )
  ORDER BY b.nachname,f.beginn;