SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
CREATE VIEW [test].[Belege_SKR_F02] AS
SELECT [Periode]
     , [Kostenstelle]
     , [Ebene1]
     , sum([Ist]) AS [Ist]
FROM (SELECT format([Invoice_Date], 'yyyy-MM') AS [Periode]
           , [Kostenstelle]
           , CASE
                 WHEN [Ebene1] = 'Kosten' THEN [Ebene2]
                 WHEN [Ebene1] = 'Anschaffungskosten' THEN 'VAK'
                 ELSE [Ebene1]
             END AS [Ebene1]
           , [Ist]
      FROM [transform].[Belege_SKR]
      WHERE [Invoice_Date] >= datefromparts(year(getdate()), 1, 1)) [V1]
GROUP BY [Periode], [Kostenstelle], [Ebene1]
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

GO
