DROP VIEW LD0VLU05;

CREATE VIEW LD0VLU05
      AS SELECT * 
      FROM LD0P0U05 KART
      WHERE (EXISTS(SELECT 'X'
            FROM LD0V1AJD AJD
            WHERE AJD.VYNAMN = 'KARTLÄGGN'
            AND (KART.ANMORGENHNR LIKE AJD.JFRDTA10
            OR KART.ORGENHNR LIKE AJD.JFRDTA10)))
	  AND	(EXISTS (SELECT 'X' FROM LD0P0SEKR SEKR
								  JOIN LD0V0ANVANDARE AJD
								  ON AJD.CSSANV=SEKR.CSSANV
								  AND SEKR.PNR=KART.PERSONNR)
							OR NOT EXISTS (SELECT 'X' FROM LD0P0SEKR SEKR WHERE SEKR.PNR=KART.PERSONNR))
WITH CHECK OPTION;