transform.NW_GW_Bestand.sql 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. SET QUOTED_IDENTIFIER ON
  2. GO
  3. SET ANSI_NULLS ON
  4. GO
  5. CREATE VIEW [transform].[NW_GW_Bestand] AS
  6. select "GC_Department"."Hauptbetrieb_ID" AS "Hauptbetrieb_ID",
  7. "GC_Department"."Hauptbetrieb_Name" AS "Hauptbetrieb_Name",
  8. "GC_Department"."Standort_ID" AS "Standort_ID",
  9. "GC_Department"."Standort_Name" AS "Standort_Name",
  10. case when "GC_Marken"."Fabrikat" is null then 'Fremd' else "GC_Marken"."Fabrikat" end AS "Fabrikat",
  11. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Model_Detail" AS "Modell_Beschreibung",
  12. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Model" AS "Model",
  13. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."FZG" AS "FZG",
  14. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Fahrzeugart" AS "Fahrzeugart",
  15. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Fahrzeugtyp" AS "Fahrzeugtyp",
  16. '' AS "Fahrzeugtyp_1",
  17. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Standtagestaffel" AS "Standtagestaffel",
  18. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Farbe" AS "Farbe",
  19. '' AS "Standort_1",
  20. '' AS "Lieferant_Einkäufer",
  21. '' AS "Name_Lieferant",
  22. '' AS "Name_Einkäufer",
  23. '' AS "FZG_Einkäufer",
  24. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."First Registration Date" AS "EZ",
  25. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Mileage Km" AS "Km_stand",
  26. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Menge" AS "Menge",
  27. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Einsatz" AS "Einsatz",
  28. 0 AS "int__Aufw_",
  29. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Standtage" AS "Standtage",
  30. 0 AS "Plan_VK_Netz_brutto",
  31. 0 AS "Plan_VK_Netz_netto",
  32. 0 AS "Plan_Vk_Platz_brutto",
  33. 0 AS "Plan_VK_Platz_netto",
  34. 0 AS "Einsatz_ori__Betrag_FIBU_",
  35. 0 AS "Einsatz_ber",
  36. convert(datetime, convert(char(8), current_timestamp, 112), 112) AS "Invoice_Date",
  37. "GC_Marken"."Order_By" AS "Fabrikat_Order_By",
  38. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Standtage_Berechnung" AS "Standtage_ER",
  39. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Accounting Date" AS "Auslief__Datum_gepl_",
  40. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Document Type" AS "Kunde",
  41. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Is Balanced" AS "Standort_Nr_AB",
  42. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Debit Or Credit" AS "Verkäufer",
  43. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Invoice Number" AS "Auslief_Datum_Zeichen",
  44. "GC_Department_Auftragsbestand"."Standort_Name" AS "Standort_Name_Auftragsbestand",
  45. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Contra Account Text" AS "AB_ja_nein",
  46. case
  47. when "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Contra Account Text" = 'Auftragsbestand' then
  48. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Vehicle_Reference_berechnet" + ' - ' +
  49. "GC_Department_Auftragsbestand"."Standort_Name" + ' - ' +
  50. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Fahrzeugtyp" + ' - ' +
  51. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Debit Or Credit" + ' - ' +
  52. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Document Type" + ' - ' +
  53. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Invoice Number"
  54. else NULL end AS "FZG_AB",
  55. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Vehicle_Reference_berechnet" AS "Vehicle_Reference_berechnet",
  56. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Posted Value" AS "Posted_Value",
  57. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Posted Count" AS "Erlös_FZG",
  58. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Document Number" AS "Tage_bis_Auslief_"
  59. from ((locosoft."NW_GW_BE_auf_NW_GW_Bestand_Cat" "NW_GW_BE_auf_NW_GW_Bestand_Cat" LEFT OUTER JOIN "data"."GC_Department" "GC_Department"
  60. on "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Hauptbetrieb" = "GC_Department"."Hauptbetrieb" and
  61. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Standort" =
  62. "GC_Department"."Standort") LEFT OUTER JOIN "data"."GC_Marken" "GC_Marken"
  63. on "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Fabrikat" = "GC_Marken"."Description")
  64. LEFT OUTER JOIN "GC"."data"."GC_Department" "GC_Department_Auftragsbestand"
  65. on "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Hauptbetrieb" =
  66. "GC_Department_Auftragsbestand"."Hauptbetrieb" and
  67. "NW_GW_BE_auf_NW_GW_Bestand_Cat"."Is Balanced" = "GC_Department_Auftragsbestand"."Standort"
  68. GO
  69. SET QUOTED_IDENTIFIER OFF
  70. GO
  71. SET ANSI_NULLS OFF
  72. GO
  73. GO