DROP VIEW LD0VLKANTACUSTSHIPOVERVIEW
;
CREATE VIEW LD0VLKANTACUSTSHIPOVERVIEW AS
SELECT SW.ID AS WELFAREID, SW.PNR, SW.BEGINDAT AS SOCIAL_FROM, SW.ENDDAT AS SOCIAL_TOM, 
  SU.SERVUNIT, SU.BEGINDAT AS UNIT_FROM, SU.ENDDAT AS UNIT_TOM, SC.SERVCATCODE, SC.BEGINDAT AS SERVCAT_FROM, 
  SC.ENDDAT AS SERVCAT_TOM FROM LD0P0SOCIALWELFARECUSTSHIP SW
  LEFT OUTER JOIN LD0P0SERVICEUNITCUSTSHIP SU ON SU.WELFAREID = SW.ID AND SW.ARCHSTATE != 5 AND SW.ARCHSTATE != 7
  LEFT OUTER JOIN LD0P0SERVICECATEGORYCUSTSHIP SC ON SC.WELFAREID = SW.ID AND SU.ARCHSTATE != 5 AND SU.ARCHSTATE != 7 AND SC.ARCHSTATE != 5 AND SC.ARCHSTATE != 7
;

