DROP VIEW LD0VAA0SERVICES
;
CREATE VIEW LD0VAA0SERVICES
AS
SELECT C20.INSNR,
C20.INSTYP,
C20.KEDJENR,
C20.ARENDENR,
C20.VERKNR,
C20.BESLUTNR,
C20.ORGID,
C20.ORGENHNR,
C20.FOMDAT,
C20.TOMDAT,
C20.HAND,
C20.MEDHAND,
C20.AKTPNR,
C20.SALFMED,
C20.UPDDAT,
C20.UPDSIGN,
C20.AVBRYT,
C20.AVBORS,
C20.INKONTO,
C20.UTKONTO,
C20.PRELTOM,
C20.ANTAL,
C20.UTFORSAV,
C20.PERIOD,
C20.VARDNHAV,
C20.ORGENHNR2,
C20.PNR,
C20.DELREHAB,
C20.BSKFAMLNR,
C20.INTDAT,
C20.UTSKRIVDAT,
C20.AVSLORSAKTYP,
C20.AVSLORSAK,
C20.AVSLORSAKSPEC,
C20.JDSTATUS,
C20.BOENDE,
C20.INGENMEDSOK, 
Q.KLARTEXT INSTYP_T, 
Q.XNUM2 PAYMENTTYPE, 
Q.XNUM29 INSTRUMENTX, 
Q.XNUM40 WORKFLOW_T,
Q_2.KLARTEXT AVBORS_T, 
Q_3.KLARTEXT AVSLORSAKTYP_T, 
Q_4.KLARTEXT AVSLORSAK_T, 
Q_5.KLARTEXT AVSLORSAKSPEC_T,
J01.NAMN ORG_T,
I.NAMN HAND_T,
I_2.NAMN MEDHAND_T
FROM LD0VLC20 C20 
INNER JOIN LD0V0Q01 Q 
ON Q.KODTYP ='INSATS' 
AND Q.KOD = C20.INSTYP
LEFT JOIN LD0V0Q01 Q_2 
ON Q_2.KODTYP ='INSAVBORS' 
AND Q_2.KOD = C20.AVBORS
LEFT JOIN LD0V0Q01 Q_3 
ON Q_3.KODTYP ='INSORSTYP' 
AND Q_3.KOD = C20.AVSLORSAKTYP
LEFT JOIN LD0V0Q01 Q_4 
ON Q_4.KODTYP ='INSORSAK' 
AND Q_4.KOD = C20.AVSLORSAK
LEFT JOIN LD0V0Q01 Q_5 
ON Q_5.KODTYP ='INSORSSPEC' 
AND Q_5.KOD = C20.AVSLORSAKSPEC
LEFT JOIN LD0V0J01 J01 
ON C20.ORGID = J01.ORGID 
AND C20.ORGENHNR = J01.ORGENHNR
LEFT JOIN LD0V0I I 
ON C20.HAND = I.HAND
LEFT JOIN LD0V0I I_2 
ON C20.MEDHAND = I_2.HAND

;