transform.Belege.sql 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. SET QUOTED_IDENTIFIER ON
  2. GO
  3. SET ANSI_NULLS ON
  4. GO
  5. CREATE VIEW [transform].[Belege] AS
  6. --Belege
  7. SELECT [Client_DB]
  8. ,
  9. --[No] AS [No],
  10. --[Name] AS [Name],
  11. --[Account Type] AS [Account Type],
  12. --[Income Balance] AS [Income Balance],
  13. --[Last Date Modified] AS [Last Date Modified],
  14. --[Entry No] AS [Entry No],
  15. --[G L Account No] AS [G L Account No],
  16. --[Posting Date] AS [Posting Date],
  17. --[Document Type] AS [Document Type],
  18. --[Document No] AS [Document No],
  19. --[Description] AS [Description],
  20. --[Bal Account No] AS [Bal Account No],
  21. [Department Code] AS [Department Code],
  22. [Make Code] AS [Make Code],
  23. --[User Id] AS [User Id],
  24. --[Source Code] AS [Source Code],
  25. --[Quantity] AS [Quantity],
  26. --[Reason Code] AS [Reason Code],
  27. --[Gen Posting Type] AS [Gen Posting Type],
  28. --[Gen Bus Posting Group] AS [Gen Bus Posting Group],
  29. --[Gen Prod Posting Group] AS [Gen Prod Posting Group],
  30. --[Bal Account Type] AS [Bal Account Type],
  31. --[Transaction No] AS [Transaction No],
  32. --[Document Date] AS [Document Date],
  33. --[External Document No] AS [External Document No],
  34. --[Source Type] AS [Source Type],
  35. --[Source No] AS [Source No],
  36. --[No Series] AS [No Series],
  37. [Branch Code] AS [Branch Code],
  38. --[Main Area] AS [Main Area],
  39. [Vin] AS [Vin],
  40. --[Book No] AS [Book No],
  41. --[Veh Source Code] AS [Veh Source Code],
  42. --[Reposted] AS [Reposted],
  43. --[Corrected] AS [Corrected],
  44. --[Correction To Curr No] AS [Correction To Curr No],
  45. --[Reposting To Curr No] AS [Reposting To Curr No],
  46. --[Code] AS [Code],
  47. [Bookkeep Date] AS [Bookkeep Date]
  48. , [Betrieb] AS [Betrieb Nr]
  49. , [Acct Nr] AS [Acct Nr]
  50. , [Betrag] AS [Betrag]
  51. --[Amount_1] AS [Amount_1],
  52. , [Text] AS [Text]
  53. , [Beleg] AS [Beleg]
  54. , [Hauptbetrieb] AS [Hauptbetrieb]
  55. , [Marke] AS [Marke]
  56. FROM (SELECT [T1].[Client_DB]
  57. ,
  58. -- [T1]."No_" AS "No"
  59. -- , [T1]."Name" AS "Name_2"
  60. -- , [T1]."Account Type" AS "Account Type"
  61. -- , [T1]."Income_Balance" AS "Income Balance"
  62. -- , [T1]."Last Date Modified" AS "Last Date Modified"
  63. -- , [T2]."Entry No_" AS "Entry No"
  64. -- , [T2]."G_L Account No_" AS "G L Account No"
  65. -- , [T2]."Posting Date" AS "Posting Date"
  66. -- , [T2]."Document Type" AS "Document Type"
  67. -- , [T2]."Document No_" AS "Document No"
  68. -- , [T2]."Description" AS "Description"
  69. -- , [T2]."Bal_ Account No_" AS "Bal Account No"
  70. [T2]."Global Dimension 1 Code" AS "Department Code"
  71. , [T2]."Global Dimension 2 Code" AS "Make Code"
  72. -- , [T2]."User ID" AS "User Id"
  73. -- , [T2]."Source Code" AS "Source Code"
  74. -- , CASE WHEN (([T2]."Document No_" LIKE 'VRGGFZ%') OR ([T2]."Document No_" LIKE 'VRGF%')) THEN ([T2]."Veh_ Source Code") WHEN ((([T2]."Document No_" LIKE 'VGUGFZ%') OR ([T2]."Document No_" LIKE 'VGGF%')) AND ([T2]."Veh_ Source Code" <> 0)) THEN (-1) ELSE (0) END AS "Quantity"
  75. -- , [T2]."Reason Code" AS "Reason Code"
  76. -- , [T2]."Gen_ Posting Type" AS "Gen Posting Type"
  77. -- , [T2]."Gen_ Bus_ Posting Group" AS "Gen Bus Posting Group"
  78. -- , [T2]."Gen_ Prod_ Posting Group" AS "Gen Prod Posting Group"
  79. -- , [T2]."Bal_ Account Type" AS "Bal Account Type"
  80. -- , [T2]."Transaction No_" AS "Transaction No"
  81. -- , [T2]."Document Date" AS "Document Date"
  82. -- , [T2]."External Document No_" AS "External Document No"
  83. -- , [T2]."Source Type" AS "Source Type"
  84. -- , [T2]."Source No_" AS "Source No"
  85. -- , [T2]."No_ Series" AS "No Series"
  86. , [T2]."Branch Code" AS "Branch Code"
  87. -- , [T2]."Main Area" AS "Main Area"
  88. , [T2]."VIN" AS "Vin"
  89. -- , [T2]."Book No_" AS "Book No"
  90. -- , [T2]."Veh_ Source Code" AS "Veh Source Code"
  91. -- , [T2]."Reposted" AS "Reposted"
  92. -- , [T2]."Corrected" AS "Corrected"
  93. -- , [T2]."Correction to curr_ No_" AS "Correction To Curr No"
  94. -- , [T2]."Reposting to curr_ No_" AS "Reposting To Curr No"
  95. -- , [T3]."Code" AS "Code"
  96. -- , [T3]."Name" AS "Name"
  97. ,[T2]."Posting Date" AS "Bookkeep Date"
  98. -- , CASE
  99. -- WHEN ([T2]."Branch Code" IN ('01BSPKW')) THEN ('10')
  100. -- WHEN ([T2]."Branch Code" IN ('02BSMOT')) THEN ('20')
  101. -- WHEN ([T2]."Branch Code" IN ('03RHF')) THEN ('30')
  102. -- WHEN ([T2]."Branch Code" IN ('04SFH')) THEN ('40')
  103. -- WHEN ([T2]."Branch Code" IN ('05WT')) THEN ('50')
  104. -- WHEN ([T2]."Branch Code" IN ('06BI')) THEN ('60')
  105. -- WHEN ([T2]."Branch Code" IN ('07TR')) THEN ('70')
  106. -- ELSE ((left([T2]."Global Dimension 1 Code", 2))) END AS "Betrieb"
  107. , [T2]."Branch Code" AS "Betrieb"
  108. , [T2]."G_L Account No_" AS "Acct Nr"
  109. , ((convert(float, [T2]."Amount"))) AS "Betrag"
  110. -- , (convert(float, [T2]."Amount")) AS "Amount_1"
  111. , CASE WHEN ((-1 * datediff(DAY, (getdate()), [T2]."Posting Date")) <= 60) THEN ([T2]."Document No_" + ' - ' + [T2]."Description" + ' - ' + [T2]."User ID") ELSE (N'Belege älter 60 Tage') END AS "Text"
  112. , CASE WHEN ((-1 * datediff(DAY, (getdate()), [T2]."Posting Date")) <= 1850) THEN ([T2]."Document No_" + ' - ' + [T2]."Description" + ' - ' + [T2]."User ID") ELSE (N'Belege älter 120 Tage') END AS "Beleg"
  113. , '1' AS "Hauptbetrieb"
  114. , CASE WHEN ([T2]."Global Dimension 2 Code" IN ('BMW', 'BMW I', 'BMW-C1', 'BMWI', 'BMW-MINI', 'BMW-MOT', 'BMWVW')) THEN ([T2]."Global Dimension 2 Code") ELSE ('Fremdfabrikat') END AS "Marke"
  115. FROM "xtract"."G_L_Account" [T1]
  116. INNER JOIN "xtract"."G_L_Entry" [T2] ON [T1]."No_" = [T2]."G_L Account No_" AND [T1].[Client_DB] = [T2].[Client_DB]
  117. --LEFT OUTER JOIN "xtract"."Department" [T3] ON [T2]."Global Dimension 1 Code" = [T3]."Code" AND T2.[Client_DB] = T3.[Client_DB]
  118. WHERE [T1]."Income_Balance" = 0
  119. -- AND [T2]."Description" NOT like ('%GuV-Konten Nullstellung%', '%GuV Konten Nullstellung%')
  120. AND [T2]."Description" NOT LIKE '%GuV-Konten Nullstellung%'
  121. AND [T2]."Description" NOT LIKE '%GuV Konten Nullstellung%'
  122. AND [T2]."Posting Date" >= convert(datetime, '2020-01-01T00:00:00.000')
  123. AND year([T2]."Posting Date") <= year(getdate())) [D5]
  124. GO
  125. SET QUOTED_IDENTIFIER OFF
  126. GO
  127. SET ANSI_NULLS OFF
  128. GO
  129. GO