SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
CREATE VIEW [x_data].[Planung_Monat] AS

SELECT [Hauptbetrieb_ID]
     , [Hauptbetrieb_Name]
     , [Standort_ID]
     , [Standort_Name]
     , [Jahr]
     , [Kostenstelle]
     , isnull([Ebene1], '') AS [Ebene1]
     , isnull([Ebene2], '') AS [Ebene2]
     , CASE
           WHEN [Ebene2] IN ('Verkaufsabh. Kosten', 'Direkte Fixkosten') THEN
               CASE
                   WHEN [Kostenstelle] = '1' THEN '1 - NA'
                   WHEN [Kostenstelle] = '2' THEN '2 - GA'
                   WHEN [Kostenstelle] = '3' THEN '3 - T&Z'
                   WHEN [Kostenstelle] = '4' THEN '4 - SC'
                   WHEN [Kostenstelle] = '5' THEN '5 - sonst. Abt.'
                   WHEN [Kostenstelle] = '0' THEN '0 - VW'
                   ELSE ''
                   END
           ELSE isnull([Ebene3], '') END AS [Ebene3]
     , isnull([Ebene4], '') AS [Ebene4]
     , isnull([Ebene5], '') AS [Ebene5]
     , [Marke]
     , isnull([Plan], 0.0) AS [Plan]
     , isnull([Wert01], 0.0) AS [Wert01]
     , isnull([Wert02], 0.0) AS [Wert02]
     , isnull([Wert03], 0.0) AS [Wert03]
     , isnull([Wert04], 0.0) AS [Wert04]
     , isnull([Wert05], 0.0) AS [Wert05]
     , isnull([Wert06], 0.0) AS [Wert06]
     , isnull([Wert07], 0.0) AS [Wert07]
     , isnull([Wert08], 0.0) AS [Wert08]
     , isnull([Wert09], 0.0) AS [Wert09]
     , isnull([Wert10], 0.0) AS [Wert10]
     , isnull([Wert11], 0.0) AS [Wert11]
     , isnull([Wert12], 0.0) AS [Wert12]

FROM [GC_CONFIG].[ari].[Planung_Monat]
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

GO
