IF EXISTS (SELECT 1 FROM SYS.VIEWS WHERE NAME='LD0V1T41')
	BEGIN
		DROP VIEW LD0V1T41
	END
;

CREATE VIEW LD0V1T41
AS SELECT * FROM LD0P0T41 URVAL
WHERE EXISTS (SELECT 'X' FROM LD0VLC C
		WHERE C.AEVERKNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 21)
   OR EXISTS (SELECT 'X' FROM LD0VLC C 
		WHERE C.AEVERKNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 22)
   OR EXISTS (SELECT 'X' FROM LD0VLC20 C20 
		WHERE C20.INSNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 23)
   OR EXISTS (SELECT 'X' FROM LD0V0H H 
		WHERE H.AKTUALNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 20)
   OR EXISTS (SELECT 'X' FROM LD0V0L L 
   		WHERE L.RESURSNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 38)
   OR EXISTS (SELECT 'X' FROM LD0V0L L 
		WHERE L.UPPDRNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 25)
   OR EXISTS (SELECT 'X' FROM LD0V0A70 A70 
		WHERE A70.FLYKTNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 40)
   OR EXISTS (SELECT 'X' FROM LD0V0A700 A700 
		WHERE A700.FLYKTNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 40)
   OR EXISTS (SELECT 'X' FROM LD0V0B B 
		WHERE B.AKTNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 39)
   OR EXISTS (SELECT 'X' FROM LD0V0E30 E30 
		WHERE E30.ATERLNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 44)
   OR EXISTS (SELECT 'X' FROM LD0V0L L 
		WHERE L.RESURSNR = URVAL.AGARNR AND
			  URVAL.AGARTYP = 47)
   OR EXISTS (SELECT 'X' FROM LD0V2U90 U90 
		WHERE U90.LNUPPDRAGNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 48)
   OR EXISTS (SELECT 'X' FROM LD0V0U10 U10 
		WHERE U10.INSKRIVNINGSNR = URVAL.AGARNR AND
		      URVAL.AGARTYP=30)
   OR EXISTS (SELECT 'X' FROM LD0V0U30 U30 
		WHERE U30.PLANNR = URVAL.AGARNR AND
		      URVAL.AGARTYP=32)
   OR EXISTS (SELECT 'X' FROM LD0V1U60 U60 
		WHERE U60.PRAKPROJNR = URVAL.AGARNR AND
		      URVAL.AGARTYP IN (33, 34, 35, 36))
   OR EXISTS (SELECT 'X' FROM LD0V0N90 N90 
		WHERE N90.UPPDRAGNR = URVAL.AGARNR AND
		      URVAL.AGARTYP=46)
   OR EXISTS (SELECT 'X' FROM LD0VLC C
		WHERE C.AEVERKNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 42)
   OR EXISTS (SELECT 'X' FROM LD0VLC20 C20 
		WHERE C20.INSNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 41)
   OR EXISTS (SELECT 'X' FROM LD0V0B B 
		WHERE B.AKTNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 45)
   OR EXISTS (SELECT 'X' FROM LD0V0H H 
		WHERE H.AKTUALNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 60)
   OR EXISTS (SELECT 'X' FROM LD0V0C C 
		WHERE C.AEVERKNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 61)
   OR EXISTS (SELECT 'X' FROM LD0V0U01 U01
		WHERE U01.KARTLAGGNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 62)
   OR EXISTS (SELECT 'X' FROM LD0V0C C 
		WHERE C.AEVERKNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 51)
   OR EXISTS (SELECT 'X' FROM LD0V0C C 
		WHERE C.AEVERKNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 52)
   OR EXISTS (SELECT 'X' FROM LD0V0C20 C20 
		WHERE C20.INSNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 53)
   OR EXISTS (SELECT 'X' FROM LD0V0N900 N900 
		WHERE N900.UPPDRAGIFONR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 63)
   OR EXISTS (SELECT 'X' FROM LD0V0U34 U34 
		WHERE U34.PLANAKTIVITETNR = URVAL.AGARNR AND
		      URVAL.AGARTYP IN (64,74))
   OR EXISTS (SELECT 'X' FROM LD0V0U35 U35 
		WHERE U35.PLATSNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 71)
   OR EXISTS (SELECT 'X' FROM LD0V0U70 U70 
		WHERE U70.ENKELPLATSNR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 66)
   OR EXISTS (SELECT 'X' FROM LD0V0N900 N900 
		WHERE N900.UPPDRAGIFONR = URVAL.AGARNR AND
		      URVAL.AGARTYP = 68)
   OR EXISTS (SELECT 'X' FROM LD0V2U90 U90 
		WHERE U90.LNUPPDRAGNR = URVAL.AGARNR AND
		      URVAL.AGARTYP=69)
   OR EXISTS (SELECT 'X' FROM LD0V0U10 U10 
		WHERE U10.INSKRIVNINGSNR = URVAL.AGARNR AND
		      URVAL.AGARTYP=70)
   OR EXISTS (SELECT 'X' FROM LD0V0U35 U35 
		WHERE U35.AKTIVITETNR = URVAL.AGARNR AND
		      URVAL.AGARTYP=71)
   OR URVAL.AGARTYP = 26;


