SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
CREATE     VIEW [transform].[OP_aus_LOC_Belege_Deb_Saldo] AS

select "GC_Department"."Hauptbetrieb_ID"                       AS "Hauptbetrieb_ID",
       "GC_Department"."Hauptbetrieb_Name"                     AS "Hauptbetrieb_Name",
       "GC_Department"."Standort_ID"                           AS "Standort_ID",
       "GC_Department"."Standort_Name"                         AS "Standort_Name",
       "OP_aus_LOC_Belege_Deb_Saldo"."Sel Name"                AS "Sel_Name",
       "OP_aus_LOC_Belege_Deb_Saldo"."Kunde"                   AS "Kunde",
       "OP_aus_LOC_Belege_Deb_Saldo"."Text"                    AS "Beleg",
       "OP_aus_LOC_Belege_Deb_Saldo"."Forderungsart"           AS "Kostenstelle",
       "OP_aus_LOC_Belege_Deb_Saldo"."Forderungsart"           AS "Bereich",
       "OP_aus_LOC_Belege_Deb_Saldo"."Staffel"                 AS "Staffel",
       "OP_aus_LOC_Belege_Deb_Saldo"."Forderungsart"           AS "Forderungsart",
       ''                                                      AS "Abwarten",
       ''                                                      AS "Leasing",
       0                                                       AS "offen",
       0                                                       AS "Rechnungsbetrag",
       "OP_aus_LOC_Belege_Deb_Saldo"."Debitorsaldo"            AS "Gesamt_offen_KD__Info_",
       "OP_aus_LOC_Belege_Deb_Saldo"."Bookkeep Date"           AS "Invoice_Date",
       "OP_aus_LOC_Belege_Deb_Saldo"."Free Form Document Text" AS "Bonus_Startguthaben",
	   
CASE 
        WHEN 0 > 0 --[Gesamt offen KD (Info)] > 0 
            THEN 'Saldo > 0'
        ELSE 'Saldo <= 0'
    END AS "Saldo größer / kleiner 0"
from locosoft."OP_aus_LOC_Belege_Deb_Saldo" "OP_aus_LOC_Belege_Deb_Saldo"
         LEFT OUTER JOIN "data"."GC_Department" "GC_Department"
                         on "OP_aus_LOC_Belege_Deb_Saldo"."Hauptbetrieb" = "GC_Department"."Hauptbetrieb" and
                            "OP_aus_LOC_Belege_Deb_Saldo"."Standort" = "GC_Department"."Standort"
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

GO
