DROP VIEW LD0VAAYSERVICES
;
CREATE VIEW LD0VAAYSERVICES
AS
SELECT C20.*, 
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,
Q_6.KLARTEXT AVSLORSSTATSOKANDE_T,
Q_7.KLARTEXT AVSLORSSTATMEDSOKANDE_T,
Q_8.KLARTEXT AVSLORSSTATHUSHALL_T,
Q_9.KLARTEXT BOENDE_T,
J01.NAMN ORG_T,
I.NAMN HAND_T,
I_2.NAMN MEDHAND_T
FROM LD0VYC20 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 LD0V0Q01 Q_6 
ON Q_6.KODTYP ='SCBKODAVSL' 
AND Q_6.KOD = C20.AVSLORSSTATSOKANDE
LEFT JOIN LD0V0Q01 Q_7 
ON Q_7.KODTYP ='SCBKODAVSL' 
AND Q_7.KOD = C20.AVSLORSSTATMEDSOKANDE
LEFT JOIN LD0V0Q01 Q_8 
ON Q_8.KODTYP ='SCBKODAVSL' 
AND Q_8.KOD = C20.AVSLORSSTATHUSHALL
LEFT JOIN LD0V0Q01 Q_9 
ON Q_9.KODTYP ='SCBKODBOEN' 
AND Q_9.KOD = C20.BOENDE
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
;