NW_GW_Bestand_NW.sql 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. select T1."StockbookNumber" as "Stockbooknumber",
  2. T1."Franchise" as "Franchise",
  3. T1."ModelCode" as "Modelcode",
  4. T1."ACSStatus" as "Acsstatus",
  5. T1."VariantCode" as "Variantcode",
  6. T1."VehicleDescriptio001" as "Vehicledescriptio001",
  7. T1."VehicleDescriptio002" as "Vehicledescriptio002",
  8. T1."VehicleDescriptio003" as "Vehicledescriptio003",
  9. T1."VehicleDescriptio004" as "Vehicledescriptio004",
  10. T1."PhysicalBranch" as "Physicalbranch",
  11. T1."FullChassis" as "Fullchassis",
  12. T1."RegistrationNumber" as "Registrationnumber",
  13. T1."RegDate" as "Regdate",
  14. T1."CustomerName" as "Customername",
  15. T1."CustomerAddress001" as "Customeraddress001",
  16. T1."CustomerAddress002" as "Customeraddress002",
  17. T1."CustomerAddress003" as "Customeraddress003",
  18. T1."CustomerAddress004" as "Customeraddress004",
  19. T1."CustomerAddress005" as "Customeraddress005",
  20. T1."CusAddressPostcode" as "Cusaddresspostcode",
  21. T1."InvoiceName" as "Invoicename",
  22. T1."InvoiceAddress001" as "Invoiceaddress001",
  23. T1."InvoiceAddress002" as "Invoiceaddress002",
  24. T1."InvoiceAddress003" as "Invoiceaddress003",
  25. T1."InvoiceAddress004" as "Invoiceaddress004",
  26. T1."InvoiceAddress005" as "Invoiceaddress005",
  27. T1."InvAddressPostcode" as "Invaddresspostcode",
  28. T1."CustomerOrderNo" as "Customerorderno",
  29. T1."OrderDate" as "Orderdate",
  30. T1."SOrderType" as "Sordertype",
  31. T1."SalesExecutive001" as "Salesexecutive001",
  32. T1."InvoiceAccount" as "Invoiceaccount",
  33. T1."CustomerAccount" as "Customeraccount",
  34. T1."InvoiceTotal" as "Invoicetotal",
  35. T1."LatestProfitValue" as "Latestprofitvalue_DB1",
  36. T1."Cost" as "Cost_EW",
  37. T1."MainInvoiceTotal" as "Maininvoicetotal",
  38. T1."ConsignmentTotal" as "Consignmenttotal",
  39. T1."OverallSaleNet" as "Overallsalenet_Erlös_FZG",
  40. T1."RecovOptionPrice015" as "Recovoptionprice015_VK-Hilfe",
  41. T1."SupplierName" as "Suppliername_2",
  42. T1."Client_DB" as "Client Db",
  43. T2."VehicleType" as "Vehicletype",
  44. T2."VehicleNumber" as "Vehiclenumber",
  45. T2."InvoiceNumber" as "Invoicenumber",
  46. T2."InvoiceSequence" as "Invoicesequence",
  47. T2."InvoiceDate" as "Invoicedate",
  48. T2."InvoiceValue" as "Invoicevalue",
  49. T3."FranchiseCode" as "Franchisecode",
  50. T3."FullName001" as "Fullname001",
  51. T3."FullName002" as "Fullname002",
  52. T3."FullName003" as "Fullname003",
  53. T4."LocationCode" as "Locationcode",
  54. T4."Description" as "Description",
  55. T4."LocationName" as "Locationname",
  56. T5."UserID" as "Userid",
  57. T5."UserName" as "Username",
  58. T6."OrderType" as "Ordertype",
  59. T6."Description001" as "Description001",
  60. T6."Description002" as "Description002",
  61. T6."Description003" as "Description003",
  62. T1."Client_DB" as "Hauptbetrieb_ID",
  63. '' as "Hauptbetrieb_Name",
  64. T4."LocationCode" as "Standort_ID",
  65. T4."LocationCode" + ' - ' + T4."Description" as "Standort_Name",
  66. T5."UserName" as "Verkäufer",
  67. T3."FullName002" as "Fabrikat",
  68. (left((ucase(T1."VehicleDescriptio002")),4)) as "Model",
  69. CASE WHEN (T1."FullChassis" IS NOT NULL) THEN ((rtrim((((T1."StockbookNumber"))))) + '/' + T1."FullChassis" + ' - ' + (CASE WHEN (((('Neuwagen')) = 'Neuwagen') and (T7."VehicleMagicNumber" IS NOT NULL)) THEN ('VFW NW') ELSE ('NW') END)) ELSE ((rtrim((((T1."StockbookNumber"))))) + ' - ' + (CASE WHEN (((('Neuwagen')) = 'Neuwagen') and (T7."VehicleMagicNumber" IS NOT NULL)) THEN ('VFW NW') ELSE ('NW') END)) END as "FZG",
  70. T1."CustomerAccount" + ' - ' + T1."CustomerName" as "Kunde",
  71. T7."VehicleMagicNumber" as "Vehiclemagicnumber_MK_Demo_Veh",
  72. T7."VehicleType" as "Vehicletype_MK_Demo_Veh",
  73. ('Neuwagen') as "Fahrzeugart",
  74. CASE WHEN (((('Neuwagen')) = 'Neuwagen') and (T7."VehicleMagicNumber" IS NOT NULL)) THEN ('VFW NW') ELSE ('NW') END as "Fahrzeugtyp",
  75. '' as "Konto",
  76. '' as "Fahrzeugtyp_1",
  77. T6."OrderType" + ' - ' + T6."Description002" as "Kundenart",
  78. T2."VehicleType" + (rtrim((((T2."VehicleNumber"))))) + '/' + (right(T1."FullChassis",7)) + ' - ' + T4."LocationCode" + ' - ' + (CASE WHEN (((('Neuwagen')) = 'Neuwagen') and (T7."VehicleMagicNumber" IS NOT NULL)) THEN ('VFW NW') ELSE ('NW') END) + ' - ' + T5."UserName" + ' - ' + T1."CustomerName" + ' - ' + (convert(varchar(50), year(T2."InvoiceDate")) + '-' + convert(varchar(50), month(T2."InvoiceDate")) + '-' + convert(varchar(50), day(T2."InvoiceDate"))) as "FZG_Detail",
  79. (left(T1."CusAddressPostcode",1)) as "PLZ_1",
  80. (left(T1."CusAddressPostcode",2)) as "PLZ_2",
  81. (left(T1."CusAddressPostcode",3)) as "PLZ_3",
  82. (left(T1."CusAddressPostcode",4)) as "PLZ_4",
  83. T1."CusAddressPostcode" as "PLZ Code_Deb",
  84. T1."SupplierName" as "Name_Lieferant_2",
  85. T1."VehicleDescriptio002" as "Modell_Beschreibung",
  86. '' as "Name_Einkäufer",
  87. CASE WHEN (T1."LatestProfitValue" < 0) THEN ('DB1 < 0') ELSE ('DB1 > 0') END as "DB1 < 0",
  88. 1 as "Menge",
  89. T1."OverallSaleNet" as "Erlös_FZG",
  90. T1."OverallSaleNet" - T1."LatestProfitValue" as "Einsatz FZG",
  91. T1."RecovOptionPrice015" as "Boni",
  92. T1."OverallSaleNet" - (T1."OverallSaleNet" - T1."LatestProfitValue") as "DB1_berechnet",
  93. (getdate()) as "Invoice Date",
  94. T1."ConsignmentDate" as "Consignmentdate",
  95. T1."EstimDeliveryDate" as "Estimdeliverydate",
  96. T1."EstimDateReceived" as "Estimdatereceived",
  97. (-1 * datediff(day, (getdate()), T1."ConsignmentDate")) as "Standtage",
  98. CASE WHEN (((-1 * datediff(day, (getdate()), T1."ConsignmentDate"))) BETWEEN 0 AND 30) THEN ('0 - 30 Tage') WHEN (((-1 * datediff(day, (getdate()), T1."ConsignmentDate"))) BETWEEN 31 AND 60) THEN ('31 - 60 Tage') WHEN (((-1 * datediff(day, (getdate()), T1."ConsignmentDate"))) BETWEEN 61 AND 90) THEN ('61 - 90 Tage') WHEN (((-1 * datediff(day, (getdate()), T1."ConsignmentDate"))) BETWEEN 91 AND 180) THEN ('91 - 180 Tage') WHEN (((-1 * datediff(day, (getdate()), T1."ConsignmentDate"))) BETWEEN 181 AND 360) THEN ('181 - 360 Tage') WHEN (((-1 * datediff(day, (getdate()), T1."ConsignmentDate"))) > 360) THEN ('> 360 Tage') ELSE null END as "Standtagestaffel",
  99. T1."ColourWheelbaseDesc" as "Colourwheelbasedesc",
  100. T1."ColourWheelbaseDesc" as "Farbe",
  101. T1."PhysicalBranch" as "Standort_1",
  102. T1."SupplierName" as "Suppliername",
  103. T1."SupplierName" as "Name_Lieferant",
  104. '' as "Lieferant/Einkäufer",
  105. '' as "Einkäufer",
  106. '' as "FZG_Einkäufer",
  107. '' as "EZ",
  108. '' as "Km-stand",
  109. '' as "Bestandsart",
  110. T1."Cost" as "Einsatz"
  111. from (((((("AUTOLINE"."import"."VS_NewVehicleStock" T1 left outer join "AUTOLINE"."import"."VS_InvoiceStockFile" T2 on (T1."SalesInvoiceNumber" = T2."InvoiceNumber") and (T1."Client_DB" = T2."Client_DB")) left outer join "AUTOLINE"."import"."DD_FranchiseRecords" T3 on T1."Franchise" = T3."FranchiseCode") left outer join "AUTOLINE"."import"."GB_CompanyLocations" T4 on T1."SellingBranch" = T4."LocationCode") left outer join "AUTOLINE"."import"."GB_UserDetails" T5 on T1."SalesExecutive001" = T5."UserID") left outer join "AUTOLINE"."import"."VS_SalesOrderTypes" T6 on (T1."SOrderType" = T6."OrderType") and (T1."Client_DB" = T6."Client_DB")) left outer join "AUTOLINE"."import"."MK_DemonstrationVehicles" T7 on (T1."CRMVehicleMagic" = T7."VehicleMagicNumber") and (T7."Client_DB" <> '00'))
  112. where (((((T1."SalesInvoiceNumber" IS NULL) or (T1."SalesInvoiceNumber" = 0)) or (T1."InvoiceTotal" = 0)) and (T1."Client_DB" <> '00')) and (T1."ConsignmentDate" IS NOT NULL))
  113. -- order by "Stockbooknumber" asc