 
Create OR ALTER VIEW LD0APILMPersons   
AS SELECT             
PER.PNR   AS 'PERSONID',     
PER.KUNDNUMMER AS 'CUSTOMERNUMBER',            
PER.FODDAT  AS 'BIRTHDATE',            
PER.KON   AS 'GENDER',            
KOD1.KLARTEXT AS 'MARITALSTATUS',            
PER.NYCKKOD  AS 'KEYCODE',            
PER.OMRADE  AS 'AREAID' ,          
KOD6.KLARTEXT AS 'Area' ,        
KOD4.XTXT1 AS 'CITIZENSHIPCODE',  
KOD2.KLARTEXT AS 'CITIZENSHIP',    
KOD5.XTXT1  AS 'BORNCOUNTRYCODE',   
KOD3.KLARTEXT AS 'BORNCOUNTRY',  
KOD4.XTXT1  AS 'CITIZENSHIPCODEPOPULATIONREGISTRY',          
KOD4.KLARTEXT AS 'CITIZENSHIPPOPULATIONREGISTRY',          
KOD5.XTXT1  AS 'BORNCOUNTRYCODEPOPULATIONREGISTRY',          
KOD5.KLARTEXT AS 'BORNCOUNTRYPOPULATIONREGISTRY'  ,        
KOD7.KLARTEXT AS 'MUNICIPALITYDISTRICT' ,        
KOD8.KLARTEXT AS 'SERVICEAREA',        
PER.CIVKOD AS 'MARITALSTATUSID'  ,   
PER.AVREGDAT AS 'DEREGISTRATIONDATE',  
PER.AVREGORS AS 'DEREGISTRATIONCODE',  
KOD9.KLARTEXT AS 'DEREGISTRATION'  
FROM LD0P0A PER     
LEFT OUTER JOIN LD0V0Q01 KOD1 ON KOD1.KODTYP = 'CIVS' AND KOD1.KOD = PER.CIVKOD             
LEFT OUTER JOIN LD0V0Q01 KOD2 ON KOD2.KODTYP = 'LAND' AND KOD2.KOD = PER.MEDBSKAP            
LEFT OUTER JOIN LD0V0Q01 KOD3 ON KOD3.KODTYP = 'LAND' AND KOD3.KOD = PER.FODLAND            
LEFT OUTER JOIN LD0P0Q01 KOD4 ON KOD4.KODTYP = 'LAND' AND KOD4.KOD = PER.MEDBSKAP            
LEFT OUTER JOIN LD0P0Q01 KOD5 ON KOD5.KODTYP = 'LAND' AND KOD5.KOD = PER.FODLAND            
lEFT OUTER JOIN LD0V0Q01 KOD6 ON KOD6.KODTYP = 'OMRÅDE' AND  KOD6.KOD = PER.OMRADE        
LEFT OUTER JOIN LD0V0Q01 KOD7 ON KOD7.KODTYP = 'KOMMUNDEL' AND KOD7.KOD = PER.KOMDEL        
LEFT OUTER JOIN LD0V0Q01 KOD8 ON KOD8.KODTYP = 'BETJOMR' AND KOD8.KOD = PER.BETJOMR        
LEFT OUTER JOIN LD0V0Q01 KOD9 ON KOD9.KODTYP = 'AVREGORSAK' AND KOD9.KOD = PER.AVREGORS        
WHERE (EXISTS (SELECT 'X' FROM LD0P0U90 U90 WHERE U90.PNR=PER.PNR)  
 OR EXISTS (SELECT 'X' FROM LD0P0U10 U10 WHERE U10.PERSONNR=PER.PNR))  
  