DROP VIEW LD0VAA0Searchpayments
;
CREATE VIEW LD0VAA0Searchpayments AS 
SELECT  F.KONTONR,
		F.BELOPP,
		F.AGARTYP as BETAGARTYP,
		F.AGARNR as BETAGARNR,
		F.NAMN AS BETNAMN,
		F.ADRESS AS BETADRESS,
		F.ORT AS BETORT,
		F.POSTNR AS BETPOSTNR,
		F.COADR AS BETCOADR,
		F.LOKBET,
		F.BETALNR,
		F.FEL,
		F.STATUS AS BETSTATUS,
		F.BETTYP,Q01_1.KLARTEXT AS BETTYP_T,
		F.BETSATT,Q01.KLARTEXT AS BETSATT_T,
		F.CLEAR,
		F.BESFATT,
		F.OCR,F.UPDSIGN,
		F.UPDDAT,
		F.INTDAT,
		F.AVSERMANAD,
		F.BETDAT AS BETALDATUM,
		F.BETMED,F.VERNR AS VERIFIKAT,
		F.RAKNNR AS RAKNINGSNR,
		F.BOKDAT AS BOKDATUM,
		F.EJINT AS BOKFORING,
		A.NAMN AS PERSONNAME,
		A.PNR,A.ORT,
		A.ADRESS,
		A.FODDAT,
		A.POSTNR,
		A.COADR AS PERSONCOADDRESS,
		A.KON,A.GRUPP,
		I.HAND AS CASEWORKERID,
		I.NAMN AS CASEWORKER,
		I2.HAND AS COCASEWORKERID,
		I2.NAMN AS COCASEWORKER,C20.ORGID,C20.ORGENHNR,J01.NAMN AS ORGNAMN,
		C20.FOMDAT AS INSFOMDAT,
		C20.TOMDAT AS INSTOMDAT,
		OMR.NAMN OMRADE_NAMN,
		A.KUNDNUMMER 
FROM LD0V0F F 
	INNER JOIN LD0V0C20 C20 ON C20.INSNR = F.INSNR 
	JOIN LD0V0A A ON A.PNR = C20.AKTPNR
	 LEFT OUTER JOIN LD0VAA0OMRADENKO OMR ON A.NYCKKOD = OMR.NYCKKOD 
	 LEFT OUTER JOIN LD0V0J01 J01 ON J01.ORGID = C20.ORGID AND J01.ORGENHNR = C20.ORGENHNR 
	 LEFT OUTER JOIN LD0V0I I ON C20.HAND = I.HAND 
	 LEFT OUTER JOIN LD0V0I I2 ON C20.MEDHAND = I2.HAND 
	 LEFT OUTER JOIN LD0V0Q01 Q01 ON Q01.KODTYP = 'BETALSATT' AND Q01.KOD = F.BETSATT 
	 LEFT OUTER JOIN LD0V0Q01 Q01_1 ON Q01_1.KODTYP = 'BETALTYP' AND Q01_1.KOD = F.BETTYP 
WHERE (F.BETTYP <>	 90) AND (F.BETSATT > 0) AND (F.BETSATT < 90) AND (F.STATUS < 9) 
;