Belege.sql 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. select T1."No_" as "No",
  2. T1."Name" as "Name",
  3. T1."Account Type" as "Account Type",
  4. T1."Income_Balance" as "Income Balance",
  5. T1."Last Date Modified" as "Last Date Modified",
  6. T2."Entry No_" as "Entry No",
  7. T2."G_L Account No_" as "G L Account No",
  8. T2."Posting Date" as "Posting Date",
  9. T2."Document Type" as "Document Type",
  10. T2."Document No_" as "Document No",
  11. T2."Description" as "Description",
  12. T2."Bal_ Account No_" as "Bal Account No",
  13. T2."Global Dimension 1 Code" as "Department Code",
  14. T2."Global Dimension 2 Code" as "Make Code",
  15. T2."User ID" as "User Id",
  16. T2."Source Code" as "Source Code",
  17. 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",
  18. T2."Reason Code" as "Reason Code",
  19. T2."Gen_ Posting Type" as "Gen Posting Type",
  20. T2."Gen_ Bus_ Posting Group" as "Gen Bus Posting Group",
  21. T2."Gen_ Prod_ Posting Group" as "Gen Prod Posting Group",
  22. T2."Bal_ Account Type" as "Bal Account Type",
  23. T2."Transaction No_" as "Transaction No",
  24. T2."Document Date" as "Document Date",
  25. T2."External Document No_" as "External Document No",
  26. T2."Source Type" as "Source Type",
  27. T2."Source No_" as "Source No",
  28. T2."No_ Series" as "No Series",
  29. T2."Branch Code" as "Branch Code",
  30. T2."Main Area" as "Main Area",
  31. T2."VIN" as "Vin",
  32. T2."Book No_" as "Book No",
  33. T2."Veh_ Source Code" as "Veh Source Code",
  34. T2."Reposted" as "Reposted",
  35. T2."Corrected" as "Corrected",
  36. T2."Correction to curr_ No_" as "Correction To Curr No",
  37. T2."Reposting to curr_ No_" as "Reposting To Curr No",
  38. T3."Code" as "Code",
  39. T3."Name" as "Name",
  40. T2."Posting Date" as "Bookkeep Date",
  41. CASE WHEN (T2."Branch Code" = 'BUR') THEN ('10') WHEN (T2."Branch Code" = 'MUE') THEN ('20') ELSE ((left(T2."Global Dimension 1 Code",2))) END as "Betrieb",
  42. T2."G_L Account No_" as "Acct Nr",
  43. ((convert(float, T2."Amount"))) as "Betrag",
  44. (convert(float, T2."Amount")) as "Amount_1",
  45. CASE WHEN ((day((now()) - T2."Posting Date")) <= 120) THEN (T2."Document No_" + ' - ' + T2."Description" + ' - ' + T2."User ID") ELSE ('Belege älter 120 Tage') END as "Text",
  46. '1' as "Hauptbetrieb",
  47. 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"
  48. from "Vogl7x"."dbo"."BMW AH Vogl$G_L Account" T1,
  49. ("Vogl7x"."dbo"."BMW AH Vogl$G_L Entry" T2 left outer join "Vogl7x"."dbo"."BMW AH Vogl$Department" T3 on T2."Global Dimension 1 Code" = T3."Code")
  50. where (T1."No_" = T2."G_L Account No_")
  51. and ((((T1."Income_Balance" = 0) and (not T2."Description" IN ('GuV-Konten Nullstellung','GuV Konten Nullstellung'))) and (T2."Posting Date" >= convert(datetime, '2020-01-01 00:00:00.000'))) and ((od_year(T2."Posting Date")) <= (od_year((now())))))