load.V_Bestand.sql 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. SET QUOTED_IDENTIFIER ON
  2. GO
  3. SET ANSI_NULLS ON
  4. GO
  5. CREATE VIEW [load].[V_Bestand]
  6. AS
  7. SELECT convert(varchar(20), [Client_DB]) AS [Client_DB]
  8. , convert(varchar(50), [Modellbez]) AS [Modellbez]
  9. , convert(varchar(100), [FZG]) AS [FZG]
  10. , convert(varchar(20), [Location Code]) AS [Location Code]
  11. , convert(varchar(20), [VB_Einkauf]) AS [VB_Einkauf]
  12. , convert(decimal(28, 8), [Standtage_ori]) AS [Standtage_ori]
  13. , convert(varchar(20), [EZ/Eingang]) AS [EZ/Eingang]
  14. , convert(varchar(50), [Farbe]) AS [Farbe]
  15. , convert(decimal(28, 8), [Einsatz]) AS [Einsatz]
  16. , convert(datetime, [Invoice Date]) AS [Invoice Date]
  17. , convert(decimal(28, 8), [Standtage]) AS [Standtage]
  18. , convert(decimal(28, 8), [gepl. VK]) AS [gepl. VK]
  19. , convert(varchar(20), [Händlerstatus]) AS [Händlerstatus]
  20. , convert(decimal(28, 8), [UPE]) AS [UPE]
  21. , convert(varchar(50), [Model]) AS [Model]
  22. , convert(varchar(50), [Standtagestaffel]) AS [Standtagestaffel]
  23. , convert(decimal(28, 8), [Tage letzte Preisänderung_ori]) AS [Tage letzte Preisänderung_ori]
  24. , convert(decimal(28, 8), [Tage seit Erstzul.]) AS [Tage seit Erstzul.]
  25. , convert(decimal(28, 8), [Tag_Dashboard]) AS [Tag_Dashboard]
  26. , convert(decimal(28, 8), [Monat_Dashboard]) AS [Monat_Dashboard]
  27. , convert(decimal(28, 8), [Jahr_Dashboard]) AS [Jahr_Dashboard]
  28. , convert(varchar(20), [Fahrzeugart]) AS [Fahrzeugart]
  29. , convert(varchar(20), [Fahrzeugtyp]) AS [Fahrzeugtyp]
  30. , convert(varchar(20), [Fabrikat]) AS [Fabrikat]
  31. , convert(varchar(10), [Fabrikat_Sortierung]) AS [Fabrikat_Sortierung]
  32. , convert(varchar(20), [Hauptbetrieb_ID]) AS [Hauptbetrieb_ID]
  33. , convert(varchar(50), [Hauptbetrieb_Name]) AS [Hauptbetrieb_Name]
  34. , convert(varchar(20), [Standort_ID]) AS [Standort_ID]
  35. , convert(varchar(50), [Standort_Name]) AS [Standort_Name]
  36. FROM (SELECT [Bestand].[Client_DB] AS [Client_DB]
  37. -- , Bestand.[Hauptbetrieb]
  38. -- , Bestand.[Fabrikat]
  39. , [Bestand].[Modellbez] AS [Modellbez]
  40. -- , Bestand.[Fahrzeugart]
  41. , [Bestand].[FZG] AS [FZG]
  42. , [Bestand].[Location Code] AS [Location Code]
  43. , [Bestand].[VB_Einkauf] AS [VB_Einkauf]
  44. , [Bestand].[Standtage_ori] AS [Standtage_ori]
  45. , [Bestand].[EZ/Eingang] AS [EZ/Eingang]
  46. , [Bestand].[Farbe] AS [Farbe]
  47. , [Bestand].[Einsatz] AS [Einsatz]
  48. , [Bestand].[Invoice Date] AS [Invoice Date]
  49. -- , Bestand.[Standtage] as [Standtage_alt]
  50. , [Bestand].[Standtage_ori] * 1.0 / count([Bestand].[Client_DB]) OVER (PARTITION BY ([Bestand].[FZG])) AS [Standtage]
  51. , [Bestand].[gepl. VK] AS [gepl. VK]
  52. -- , Bestand.[Standort]
  53. , [Bestand].[Händlerstatus] AS [Händlerstatus]
  54. , [Bestand].[UPE] AS [UPE]
  55. -- , Bestand.[Fahrzeugtyp]
  56. , [Bestand].[Model] AS [Model]
  57. , [Bestand].[Standtagestaffel] AS [Standtagestaffel]
  58. , [Bestand].[Tage letzte Preisänderung_ori] AS [Tage letzte Preisänderung_ori]
  59. , [Bestand].[Tage seit Erstzul.] AS [Tage seit Erstzul.]
  60. , [Bestand].[Tag_Dashboard] AS [Tag_Dashboard]
  61. , [Bestand].[Monat_Dashboard] AS [Monat_Dashboard]
  62. , [Bestand].[Jahr_Dashboard] AS [Jahr_Dashboard]
  63. , [Fahrzeugtyp].[Zuordnung_Fahrzeugart] AS [Fahrzeugart]
  64. , [Fahrzeugtyp].[Inventory Posting Group] AS [Fahrzeugtyp]
  65. , isnull([Marke].[Fabrikat], 'Fremd') AS [Fabrikat]
  66. , [Marke].[Fabrikat_Sortierung] AS [Fabrikat_Sortierung]
  67. , [Standort].[Hauptbetrieb_ID] AS [Hauptbetrieb_ID]
  68. , [Standort].[Hauptbetrieb_Name] AS [Hauptbetrieb_Name]
  69. , [Standort].[Standort_ID] AS [Standort_ID]
  70. , [Standort].[Standort_Name] AS [Standort_Name]
  71. FROM [transform].[NW_GW_BE_neu] [Bestand]
  72. LEFT JOIN [x_data].[Marke] [Marke] ON [Bestand].[Make Code_Vehicle] = [Marke].[Make Code]
  73. LEFT JOIN [x_data].[AH_Standort] [Standort] ON [Bestand].[Client_DB] = [Standort].[Client_DB]
  74. AND [Bestand].[Location Code] = [Standort].[Branch Code]
  75. LEFT JOIN [x_data].[Fahrzeugtyp] [Fahrzeugtyp] ON [Fahrzeugtyp].[Inventory Posting Group] = [Bestand].[Inventory Posting Group]) AS [V1]
  76. GO
  77. SET QUOTED_IDENTIFIER OFF
  78. GO
  79. SET ANSI_NULLS OFF
  80. GO
  81. GO