DROP VIEW LD0V1C
;
CREATE VIEW LD0V1C
      AS SELECT * 
      FROM LD0P0C PERSONURVAL
      WHERE EXISTS(SELECT 'X'
            FROM LD0V0AJD AJD
            WHERE AJD.VYNAMN = 'FUTRED'
            AND PERSONURVAL.TMARK = 0
            AND PERSONURVAL.AEVERKTYP >= AJD.JFRDTA1
            AND PERSONURVAL.AEVERKTYP <= AJD.JFRDTA2
            AND PERSONURVAL.ORGID = AJD.JFRDTA3
            AND PERSONURVAL.ORGENHNR LIKE AJD.JFRDTA10)
			AND (EXISTS (SELECT 'X' FROM LD0P0SEKR SEKR
								  JOIN LD0V0ANVANDARE AJD
								  ON AJD.CSSANV=SEKR.CSSANV
								  AND SEKR.PNR=PERSONURVAL.AKTPNR
								  )
			OR NOT EXISTS (SELECT 'X' FROM LD0P0SEKR SEKR WHERE SEKR.PNR=PERSONURVAL.AKTPNR
								  ))
WITH CHECK OPTION
;