IF NOT EXISTS(SELECT 1 FROM sys.columns 
          WHERE Name = N'TOMDAT'
          AND Object_ID = Object_ID(N'LD0P0H30'))
BEGIN
ALTER TABLE LD0P0H30 ADD
	TOMDAT VARCHAR(8) NULL
END
;
IF EXISTS (SELECT 1 FROM SYS.VIEWS WHERE NAME='LD0V0H30')
BEGIN
DROP VIEW LD0V0H30
END
;
CREATE VIEW LD0V0H30 AS SELECT * FROM LD0P0H30
;

IF EXISTS (SELECT 1 FROM SYS.VIEWS WHERE NAME='LD0VAA0SEARCHINQUIRY')
BEGIN
DROP VIEW LD0VAA0SEARCHINQUIRY
END
;
CREATE VIEW LD0VAA0SEARCHINQUIRY AS 
SELECT H30.FORFRNR ,
H30.FORFR AS INQUIRYTYP ,
H30.FDATUM ,
H30.TOMDAT,
H30.FVEM AS FROMWHO ,
H30.FORSAK AS REASON ,
H30.FALDER AS AGE ,
H30.FKOEN AS GENDER ,
H30.HAND ,
H30.ORGID ,
H30.ORGENHNR ,
H30.UPDDAT ,
H30.UPDSIGN ,
CONCAT(H30.FTEXT1,H30.FTEXT2,H30.FTEXT3,H30.FTEXT4) AS FTEXT ,
H30.MEDHAND ,
H30.ORGENHNR2 ,
H30.ANTALBARN AS NUMBEROFCHILDREN ,
F01.KLARTEXT AS INQUIRYTYPTEXT ,
F02.KLARTEXT AS FROMWHOTEXT ,
F03.KLARTEXT AS REASONTEXT ,
I01.NAMN AS CASEWORKERNAME ,
J01.NAMN AS ORGNAME FROM LD0V0H30 H30 
LEFT JOIN LD0V0Q01 F01 ON F01.KODTYP = 'FORFRAGAN' AND F01.KOD = H30.FORFR 
LEFT JOIN LD0V0Q01 F02 ON F02.KODTYP = 'FORFVEM' AND F02.KOD = H30.FVEM 
LEFT JOIN LD0V0Q01 F03 ON F03.KODTYP = 'FORFORSAK' AND F03.KOD = H30.FORSAK 
LEFT JOIN LD0V0I I01 ON I01.HAND = H30.HAND LEFT JOIN LD0V0J01 J01 ON J01.ORGENHNR = H30.ORGENHNR 
;