SELECT "Unit Number" AS "Unit Number",
	"Basis Number_2" AS "Basis Number_2",
	"Ecc Status" AS "Ecc Status",
	"Vehicle Type_2" AS "Vehicle Type_2",
	"Transact Date_2" AS "Transact Date_2",
	"Handler_2" AS "Handler_2",
	"Car Creation Date" AS "Car Creation Date",
	"Pmt Term" AS "Pmt Term",
	"Small Accessories" AS "Small Accessories",
	"Small Inv Charge" AS "Small Inv Charge",
	"Delivery Stop Code" AS "Delivery Stop Code",
	"Price Code" AS "Price Code",
	"Discount Perc Work_2" AS "Discount Perc Work_2",
	"Discount Limit" AS "Discount Limit",
	"Internal Code" AS "Internal Code",
	"Tax Code" AS "Tax Code",
	"Unit Last Upd Dte" AS "Unit Last Upd Dte",
	"Depreciation" AS "Depreciation",
	"Transfer Tax" AS "Transfer Tax",
	"Book Keeping Code" AS "Book Keeping Code",
	"Tax Handling" AS "Tax Handling",
	"Interest Code" AS "Interest Code",
	"Mileage_2" AS "Mileage_2",
	"Purch Department" AS "Purch Department",
	"Purch Salsman Code" AS "Purch Salsman Code",
	"Purch Invno" AS "Purch Invno",
	"Purch Date" AS "Purch Date",
	"Sales Department" AS "Sales Department",
	"Sale Salesman" AS "Sale Salesman",
	"Sale Inv Number" AS "Sale Inv Number",
	"Sale Date" AS "Sale Date",
	"Scrap Code" AS "Scrap Code",
	"Unit In Change" AS "Unit In Change",
	"Bud Sale Det" AS "Bud Sale Det",
	"Bud Purch Price" AS "Bud Purch Price",
	"Bud Reg Fee" AS "Bud Reg Fee",
	"Bud Deduct Fee" AS "Bud Deduct Fee",
	"Bud Cost" AS "Bud Cost",
	"Prev Owner" AS "Prev Owner",
	"Owner" AS "Owner",
	"Purch Price Unit" AS "Purch Price Unit",
	"Cost Unit" AS "Cost Unit",
	"Sales Price Unit" AS "Sales Price Unit",
	"Reg Fee" AS "Reg Fee",
	"Interest 1" AS "Interest 1",
	"Interest 2" AS "Interest 2",
	"Next Line Unit" AS "Next Line Unit",
	"Next Line 1" AS "Next Line 1",
	"Transfer Line" AS "Transfer Line",
	"Transfer Tax Hand" AS "Transfer Tax Hand",
	"Transfer Acc Code" AS "Transfer Acc Code",
	"Transfer Tax Basis" AS "Transfer Tax Basis",
	"Transfer Tax Pct" AS "Transfer Tax Pct",
	"Transfer Sold" AS "Transfer Sold",
	"Purch Tax" AS "Purch Tax",
	"Cost Tax" AS "Cost Tax",
	"Or Mark" AS "Or Mark",
	"Transfer Date" AS "Transfer Date",
	"Stock Days" AS "Stock Days",
	"Delete Proposal" AS "Delete Proposal",
	"Transfer Bbdb" AS "Transfer Bbdb",
	"Condition Unit" AS "Condition Unit",
	"Buying Order No" AS "Buying Order No",
	"Buying Order Date" AS "Buying Order Date",
	"Pa Number" AS "Pa Number",
	"Vehicle Update" AS "Vehicle Update",
	"Latest Update" AS "Latest Update",
	"Invoice Permission" AS "Invoice Permission",
	"Location Code" AS "Location Code",
	"Account Purchase" AS "Account Purchase",
	"Account Sales" AS "Account Sales",
	"Budg Price Vat" AS "Budg Price Vat",
	"Recalc Code" AS "Recalc Code",
	"Commision No" AS "Commision No",
	"Delivery Date Veh" AS "Delivery Date Veh",
	"Reservation Date" AS "Reservation Date",
	"Reservation Person" AS "Reservation Person",
	"Reservation Text" AS "Reservation Text",
	"Freight Balance" AS "Freight Balance",
	"Trf Taxbasis Sales" AS "Trf Taxbasis Sales",
	"Trf Taxbasis Purch" AS "Trf Taxbasis Purch",
	"Sale Order No" AS "Sale Order No",
	"Unit Sold" AS "Unit Sold",
	"Trf Department" AS "Trf Department",
	"Order Arrival Date" AS "Order Arrival Date",
	"Order Confirm Date" AS "Order Confirm Date",
	"Price Label Date" AS "Price Label Date",
	"Vat Table Work" AS "Vat Table Work",
	"Vat Table Normal" AS "Vat Table Normal",
	"Vat Rate Code" AS "Vat Rate Code",
	"Transfer Vat Rc" AS "Transfer Vat Rc",
	"Cntract Due Date" AS "Cntract Due Date",
	"Contract Date" AS "Contract Date",
	"Exp Arrival Time" AS "Exp Arrival Time",
	"Dealer Marking_2" AS "Dealer Marking_2",
	"Booking Dealer Nr" AS "Booking Dealer Nr",
	"Desired Deliv Date" AS "Desired Deliv Date",
	"Valuation Date" AS "Valuation Date",
	"Ford Int Date" AS "Ford Int Date",
	"Est Sales Price" AS "Est Sales Price",
	"Est Reference No" AS "Est Reference No",
	"Reception Date" AS "Reception Date",
	"Bud Opt Price" AS "Bud Opt Price",
	"Sale Price Date" AS "Sale Price Date",
	"Purch Origin Code" AS "Purch Origin Code",
	"Price List Version" AS "Price List Version",
	"Price List Date" AS "Price List Date",
	"Unique Ident" AS "Unique Ident",
	"Vehicle Type" AS "Vehicle Type",
	"Vehicle Type Text" AS "Vehicle Type Text",
	"ECC_Status_Text" AS "ECC_Status_Text",
	"Basis Number" AS "Basis Number",
	"Transact Date" AS "Transact Date",
	"Handler" AS "Handler",
	"Register Number" AS "Register Number",
	"Chassis Number" AS "Chassis Number",
	"Car Group" AS "Car Group",
	"Car Status" AS "Car Status",
	"Fac Model Code L" AS "Fac Model Code L",
	"First Reg Date" AS "First Reg Date",
	"Latest Reg Date" AS "Latest Reg Date",
	"First Occur Date" AS "First Occur Date",
	"Expected Arr Date" AS "Expected Arr Date",
	"Arrival Date" AS "Arrival Date",
	"Salesman Buy" AS "Salesman Buy",
	"Salesman Sale" AS "Salesman Sale",
	"Model Text_2" AS "Model Text_2",
	"Orig Model Code1" AS "Orig Model Code1",
	"Orig Model Code2" AS "Orig Model Code2",
	"Colour Cf" AS "Colour Cf",
	"Trim Txt" AS "Trim Txt",
	"Model Line_2" AS "Model Line_2",
	"Workshop Model_2" AS "Workshop Model_2",
	"Fac Model Code S" AS "Fac Model Code S",
	"Classification" AS "Classification",
	"Motor Number" AS "Motor Number",
	"Key Code" AS "Key Code",
	"Year Model Cf" AS "Year Model Cf",
	"Cylinder Volume" AS "Cylinder Volume",
	"Seats" AS "Seats",
	"Declaration Date" AS "Declaration Date",
	"Declaration Place" AS "Declaration Place",
	"Declaration Number" AS "Declaration Number",
	"Equipment 1" AS "Equipment 1",
	"Equipment 2" AS "Equipment 2",
	"Equipment 3" AS "Equipment 3",
	"Equipment 4" AS "Equipment 4",
	"Mileage" AS "Mileage",
	"Misc 1 Cf" AS "Misc 1 Cf",
	"Misc 2 Cf" AS "Misc 2 Cf",
	"Misc 3 Cf" AS "Misc 3 Cf",
	"Misc 4 Cf" AS "Misc 4 Cf",
	"Misc 5 Cf" AS "Misc 5 Cf",
	"Misc 6 Cf" AS "Misc 6 Cf",
	"Misc 7 Cf" AS "Misc 7 Cf",
	"Misc 8 Cf" AS "Misc 8 Cf",
	"Misc 9 Cf" AS "Misc 9 Cf",
	"Misc 10 Cf" AS "Misc 10 Cf",
	"Motor Code" AS "Motor Code",
	"Gear Code" AS "Gear Code",
	"Drive Code" AS "Drive Code",
	"Colour Code" AS "Colour Code",
	"Trim Code" AS "Trim Code",
	"No Of Owners" AS "No Of Owners",
	"Tuv Type" AS "Tuv Type",
	"Tuv Date" AS "Tuv Date",
	"Tuv Insp" AS "Tuv Insp",
	"Asu Type" AS "Asu Type",
	"Asu Date" AS "Asu Date",
	"Asu Insp" AS "Asu Insp",
	"Type Year" AS "Type Year",
	"Available" AS "Available",
	"Cal Cost" AS "Cal Cost",
	"Cal Cost Date" AS "Cal Cost Date",
	"Stock Date" AS "Stock Date",
	"Purch Cal Date" AS "Purch Cal Date",
	"Model Line Group" AS "Model Line Group",
	"Model Type 2" AS "Model Type 2",
	"Make" AS "Make",
	"Hour Rate Table" AS "Hour Rate Table",
	"Paid Date" AS "Paid Date",
	"Latest Inv Date" AS "Latest Inv Date",
	"Purch Amount" AS "Purch Amount",
	"Dealer Number" AS "Dealer Number",
	"Dealer Marking" AS "Dealer Marking",
	"Fueltype" AS "Fueltype",
	"Service Days" AS "Service Days",
	"Hourly Repair Rate" AS "Hourly Repair Rate",
	"Workshop Pricecode" AS "Workshop Pricecode",
	"Discount Perc Work" AS "Discount Perc Work",
	"Soldmark Date" AS "Soldmark Date",
	"Make Cd_3" AS "Make Cd_3",
	"Model Line" AS "Model Line",
	"Mod Lin Specify" AS "Mod Lin Specify",
	"Make Cd_2" AS "Make Cd_2",
	"Workshop Model" AS "Workshop Model",
	"Make Cd" AS "Make Cd",
	"Model Text" AS "Model Text",
	"Orig Model Code" AS "Orig Model Code",
	"Model Type" AS "Model Type",
	"Model Group" AS "Model Group",
	"Make Code" AS "Make Code",
	"Hauptbetrieb" AS "Hauptbetrieb",
	"Standort" AS "Standort",
	"Department Type Id" AS "Department Type Id",
	"Description_2" AS "Description_2",
	"Fahrzeugart" AS "Fahrzeugart",
	"Fabrikat_ori" AS "Fabrikat_ori",
	"Modellbez" AS "Modellbez",
	"Fahrgestellnr" AS "Fahrgestellnr",
	"Farbe" AS "Farbe",
	"FZG" AS "FZG",
	"Fahrzeugtyp" AS "Fahrzeugtyp",
	"Global Make Cd" AS "Global Make Cd",
	"Description" AS "Description",
	"Einsatz" AS "Einsatz",
	"Menge" AS "Menge",
	"Heute" AS "Heute",
	"Standtage" AS "Standtage",
	"Standtagestaffel" AS "Standtagestaffel",
	"Car Letter" AS "Car Letter",
	"Fahrzeugart_Konsi" AS "Fahrzeugart_Konsi",
	"kalk_Kosten" AS "kalk_Kosten",
	"Betrieb" AS "Betrieb",
	"Seller Code" AS "Seller Code",
	"Sel Name" AS "Sel Name",
	"VB_Einkauf" AS "VB_Einkauf",
	"geplante Kosten" AS "geplante Kosten",
	"int. Aufw." AS "int. Aufw.",
	"geplanter VK" AS "geplanter VK",
	"Fabrikat_manuell" AS "Fabrikat_manuell",
	"Department_unique_change_history" AS "Department_unique_change_history",
	"Unique Ident_unique_change_history" AS "Unique Ident_unique_change_history",
	MAX("Unique Ident_unique_change_history") OVER (PARTITION BY "Unit Number") AS "MAXIMUM  (  Unique Ident_unique_change_history  )",
	"Hauptbetrieb_ID" AS "Hauptbetrieb_ID",
	"Hauptbetrieb_Name" AS "Hauptbetrieb_Name",
	"Standort_ID" AS "Standort_ID",
	"Standort_Name" AS "Standort_Name",
	"Fabrikat_GC_Marke" AS "Fabrikat_GC_Marke",
	"Fabrikat" AS "Fabrikat",
	"Fabrikat_Order_By" AS "Fabrikat_Order_By",
	"Modell_Beschreibung" AS "Modell_Beschreibung",
	"Model" AS "Model",
	"Fahrzeugtyp_1" AS "Fahrzeugtyp_1",
	"Standort_1" AS "Standort_1",
	"Lieferant/Eink�ufer" AS "Lieferant/Eink�ufer",
	"Name_Lieferant" AS "Name_Lieferant",
	"Name_Eink�ufer" AS "Name_Eink�ufer",
	"FZG_Eink�ufer" AS "FZG_Eink�ufer",
	"EZ" AS "EZ",
	"Km-stand" AS "Km-stand",
	"Plan VK Netz brutto" AS "Plan VK Netz brutto",
	"Plan VK Netz netto" AS "Plan VK Netz netto",
	"Plan Vk Platz brutto" AS "Plan Vk Platz brutto",
	"Plan VK Platz netto" AS "Plan VK Platz netto",
	"Invoice Date" AS "Invoice Date",
	"FZG_Bestand_Dashboard" AS "FZG_Bestand_Dashboard",
	"Status" AS "Status",
	"Lager / verkauft" AS "Lager / verkauft"
FROM (
	SELECT "Unit Number",
		"Basis Number_2",
		"Ecc Status",
		"Vehicle Type_2",
		"Transact Date_2",
		"Handler_2",
		"Car Creation Date",
		"Pmt Term",
		"Small Accessories",
		"Small Inv Charge",
		"Delivery Stop Code",
		"Price Code",
		"Discount Perc Work_2",
		"Discount Limit",
		"Internal Code",
		"Tax Code",
		"Unit Last Upd Dte",
		"Depreciation",
		"Transfer Tax",
		"Book Keeping Code",
		"Tax Handling",
		"Interest Code",
		"Mileage_2",
		"Purch Department",
		"Purch Salsman Code",
		"Purch Invno",
		"Purch Date",
		"Sales Department",
		"Sale Salesman",
		"Sale Inv Number",
		"Sale Date",
		"Scrap Code",
		"Unit In Change",
		"Bud Sale Det",
		"Bud Purch Price",
		"Bud Reg Fee",
		"Bud Deduct Fee",
		"Bud Cost",
		"Prev Owner",
		"Owner",
		"Purch Price Unit",
		"Cost Unit",
		"Sales Price Unit",
		"Reg Fee",
		"Interest 1",
		"Interest 2",
		"Next Line Unit",
		"Next Line 1",
		"Transfer Line",
		"Transfer Tax Hand",
		"Transfer Acc Code",
		"Transfer Tax Basis",
		"Transfer Tax Pct",
		"Transfer Sold",
		"Purch Tax",
		"Cost Tax",
		"Or Mark",
		"Transfer Date",
		"Stock Days",
		"Delete Proposal",
		"Transfer Bbdb",
		"Condition Unit",
		"Buying Order No",
		"Buying Order Date",
		"Pa Number",
		"Vehicle Update",
		"Latest Update",
		"Invoice Permission",
		"Location Code",
		"Account Purchase",
		"Account Sales",
		"Budg Price Vat",
		"Recalc Code",
		"Commision No",
		"Delivery Date Veh",
		"Reservation Date",
		"Reservation Person",
		"Reservation Text",
		"Freight Balance",
		"Trf Taxbasis Sales",
		"Trf Taxbasis Purch",
		"Sale Order No",
		"Unit Sold",
		"Trf Department",
		"Order Arrival Date",
		"Order Confirm Date",
		"Price Label Date",
		"Vat Table Work",
		"Vat Table Normal",
		"Vat Rate Code",
		"Transfer Vat Rc",
		"Cntract Due Date",
		"Contract Date",
		"Exp Arrival Time",
		"Dealer Marking_2",
		"Booking Dealer Nr",
		"Desired Deliv Date",
		"Valuation Date",
		"Ford Int Date",
		"Est Sales Price",
		"Est Reference No",
		"Reception Date",
		"Bud Opt Price",
		"Sale Price Date",
		"Purch Origin Code",
		"Price List Version",
		"Price List Date",
		"Unique Ident",
		"Vehicle Type",
		"Vehicle Type Text",
		"ECC_Status_Text",
		"Basis Number",
		"Transact Date",
		"Handler",
		"Register Number",
		"Chassis Number",
		"Car Group",
		"Car Status",
		"Fac Model Code L",
		"First Reg Date",
		"Latest Reg Date",
		"First Occur Date",
		"Expected Arr Date",
		"Arrival Date",
		"Salesman Buy",
		"Salesman Sale",
		"Model Text_2",
		"Orig Model Code1",
		"Orig Model Code2",
		"Colour Cf",
		"Trim Txt",
		"Model Line_2",
		"Workshop Model_2",
		"Fac Model Code S",
		"Classification",
		"Motor Number",
		"Key Code",
		"Year Model Cf",
		"Cylinder Volume",
		"Seats",
		"Declaration Date",
		"Declaration Place",
		"Declaration Number",
		"Equipment 1",
		"Equipment 2",
		"Equipment 3",
		"Equipment 4",
		"Mileage",
		"Misc 1 Cf",
		"Misc 2 Cf",
		"Misc 3 Cf",
		"Misc 4 Cf",
		"Misc 5 Cf",
		"Misc 6 Cf",
		"Misc 7 Cf",
		"Misc 8 Cf",
		"Misc 9 Cf",
		"Misc 10 Cf",
		"Motor Code",
		"Gear Code",
		"Drive Code",
		"Colour Code",
		"Trim Code",
		"No Of Owners",
		"Tuv Type",
		"Tuv Date",
		"Tuv Insp",
		"Asu Type",
		"Asu Date",
		"Asu Insp",
		"Type Year",
		"Available",
		"Cal Cost",
		"Cal Cost Date",
		"Stock Date",
		"Purch Cal Date",
		"Model Line Group",
		"Model Type 2",
		"Make",
		"Hour Rate Table",
		"Paid Date",
		"Latest Inv Date",
		"Purch Amount",
		"Dealer Number",
		"Dealer Marking",
		"Fueltype",
		"Service Days",
		"Hourly Repair Rate",
		"Workshop Pricecode",
		"Discount Perc Work",
		"Soldmark Date",
		"Make Cd_3",
		"Model Line",
		"Mod Lin Specify",
		"Make Cd_2",
		"Workshop Model",
		"Make Cd",
		"Model Text",
		"Orig Model Code",
		"Model Type",
		"Model Group",
		"Make Code",
		"Hauptbetrieb",
		"Standort",
		"Department Type Id",
		"Description_2",
		"Fahrzeugart",
		"Fabrikat_ori",
		"Model Text_2" AS "Modellbez",
		"Chassis Number" AS "Fahrgestellnr",
		"Farbe",
		"FZG",
		"Fahrzeugtyp",
		"Global Make Cd",
		"Fabrikat_ori" AS "Description",
		"Einsatz",
		1 AS "Menge",
		"Heute",
		"Standtage",
		"Standtagestaffel",
		"Car Letter",
		"Fahrzeugart_Konsi",
		"kalk_Kosten",
		"Location Code" AS "Betrieb",
		"Seller Code",
		"Sel Name",
		"Sel Name" AS "VB_Einkauf",
		"Bud Cost" AS "geplante Kosten",
		"Cost Unit" AS "int. Aufw.",
		"Bud Sale Det" AS "geplanter VK",
		"Fabrikat_manuell",
		"Department_unique_change_history",
		"Unique Ident_unique_change_history",
		"Hauptbetrieb_ID",
		"Hauptbetrieb_Name",
		"Standort_ID",
		"Standort_Name",
		"Fabrikat_GC_Marke",
		"Fabrikat",
		"Fabrikat_Order_By",
		"Mod Lin Specify" AS "Modell_Beschreibung",
		"Model Text_2" AS "Model",
		'' AS "Fahrzeugtyp_1",
		"Location Code" AS "Standort_1",
		"Lieferant/Eink�ufer",
		"Prev Owner" AS "Name_Lieferant",
		"Sel Name" AS "Name_Eink�ufer",
		"FZG_Eink�ufer",
		"EZ",
		"Mileage_2" AS "Km-stand",
		0 AS "Plan VK Netz brutto",
		"Bud Sale Det" AS "Plan VK Netz netto",
		0 AS "Plan Vk Platz brutto",
		0 AS "Plan VK Platz netto",
		"Heute" AS "Invoice Date",
		"FZG_Bestand_Dashboard",
		"Status",
		"Lager / verkauft",
		MAX("Unique Ident_unique_change_history") OVER (PARTITION BY "Unit Number") AS c260
	FROM (
		SELECT T1."UNIT_NUMBER" AS "Unit Number",
			CASE 
				WHEN (T1."ECC_STATUS" IN ('21', '41'))
					THEN ('Lager')
				WHEN (T1."ECC_STATUS" IN ('25', '44'))
					THEN ('verkauft')
				ELSE NULL
				END AS "Lager / verkauft",
			CASE 
				WHEN (T1."ECC_STATUS" LIKE '2%')
					THEN ('Vorlauf')
				WHEN (T1."ECC_STATUS" LIKE '4%')
					THEN ('Bestand')
				ELSE NULL
				END AS "Status",
			CASE 
				WHEN (T3."MODEL_TEXT" IS NOT NULL)
					THEN ((rtrim(T3."MODEL_TEXT")) + ' - ' + T1."UNIT_NUMBER")
				ELSE (T1."UNIT_NUMBER")
				END AS "FZG_Bestand_Dashboard",
			((getdate())) AS "Heute",
			T1."BUD_SALE_DET" AS "Bud Sale Det",
			T1."MILEAGE" AS "Mileage_2",
			(convert(VARCHAR(50), year(T3."FIRST_REG_DATE")) + '-' + convert(VARCHAR(50), month(T3."FIRST_REG_DATE")) + '-' + convert(VARCHAR(50), day(T3."FIRST_REG_DATE"))) AS "EZ",
			(rtrim(T1."UNIT_NUMBER")) + ' - ' + T8."SEL_NAME" AS "FZG_Eink�ufer",
			T8."SEL_NAME" AS "Sel Name",
			T1."PREV_OWNER" AS "Prev Owner",
			(rtrim(T1."PREV_OWNER")) + ' / ' + T8."SEL_NAME" AS "Lieferant/Eink�ufer",
			T1."LOCATION_CODE" AS "Location Code",
			T3."MODEL_TEXT" AS "Model Text_2",
			T4."MOD_LIN_SPECIFY" AS "Mod Lin Specify",
			CASE 
				WHEN (T11."Order_By" IS NULL)
					THEN (99)
				ELSE (T11."Order_By")
				END AS "Fabrikat_Order_By",
			CASE 
				WHEN (T11."Fabrikat" IS NULL)
					THEN ('Fremdfabrikat')
				ELSE (T11."Fabrikat")
				END AS "Fabrikat",
			T11."Fabrikat" AS "Fabrikat_GC_Marke",
			T10."Standort_Name" AS "Standort_Name",
			T10."Standort_ID" AS "Standort_ID",
			T10."Hauptbetrieb_Name" AS "Hauptbetrieb_Name",
			T10."Hauptbetrieb_ID" AS "Hauptbetrieb_ID",
			T9."UNIQUE_IDENT" AS "Unique Ident_unique_change_history",
			T9."DEPARTMENT" AS "Department_unique_change_history",
			CASE 
				WHEN (T7."DESCRIPTION" IN ('Opel', 'Kia'))
					THEN (T7."DESCRIPTION")
				ELSE ('Fremdfabrikat')
				END AS "Fabrikat_manuell",
			T1."COST_UNIT" AS "Cost Unit",
			T1."BUD_COST" AS "Bud Cost",
			T8."SELLER_CODE" AS "Seller Code",
			(
				CASE 
					WHEN (T1."ECC_STATUS" IN ('21', '25'))
						THEN (0)
					WHEN (T1."RECEPTION_DATE" IS NULL)
						THEN ((- 1 * datediff(day, ((getdate())), T1."PURCH_DATE")))
					ELSE ((- 1 * datediff(day, ((getdate())), T1."RECEPTION_DATE")))
					END
				) * 15 AS "kalk_Kosten",
			CASE 
				WHEN (T3."CAR_LETTER" = 'Konsi')
					THEN ('Konsi-FZG')
				ELSE ('Lagerfahrzeug')
				END AS "Fahrzeugart_Konsi",
			T3."CAR_LETTER" AS "Car Letter",
			CASE 
				WHEN (
						(
							CASE 
								WHEN (T1."ECC_STATUS" IN ('21', '25'))
									THEN (0)
								WHEN (T1."RECEPTION_DATE" IS NULL)
									THEN ((- 1 * datediff(day, ((getdate())), T1."PURCH_DATE")))
								ELSE ((- 1 * datediff(day, ((getdate())), T1."RECEPTION_DATE")))
								END
							) BETWEEN 0 AND 30
						)
					THEN ('0 - 30 Tage')
				WHEN (
						(
							CASE 
								WHEN (T1."ECC_STATUS" IN ('21', '25'))
									THEN (0)
								WHEN (T1."RECEPTION_DATE" IS NULL)
									THEN ((- 1 * datediff(day, ((getdate())), T1."PURCH_DATE")))
								ELSE ((- 1 * datediff(day, ((getdate())), T1."RECEPTION_DATE")))
								END
							) BETWEEN 31 AND 60
						)
					THEN ('31 - 60 Tage')
				WHEN (
						(
							CASE 
								WHEN (T1."ECC_STATUS" IN ('21', '25'))
									THEN (0)
								WHEN (T1."RECEPTION_DATE" IS NULL)
									THEN ((- 1 * datediff(day, ((getdate())), T1."PURCH_DATE")))
								ELSE ((- 1 * datediff(day, ((getdate())), T1."RECEPTION_DATE")))
								END
							) BETWEEN 61 AND 90
						)
					THEN ('61 - 90 Tage')
				WHEN (
						(
							CASE 
								WHEN (T1."ECC_STATUS" IN ('21', '25'))
									THEN (0)
								WHEN (T1."RECEPTION_DATE" IS NULL)
									THEN ((- 1 * datediff(day, ((getdate())), T1."PURCH_DATE")))
								ELSE ((- 1 * datediff(day, ((getdate())), T1."RECEPTION_DATE")))
								END
							) BETWEEN 91 AND 180
						)
					THEN ('91 - 180 Tage')
				WHEN (
						(
							CASE 
								WHEN (T1."ECC_STATUS" IN ('21', '25'))
									THEN (0)
								WHEN (T1."RECEPTION_DATE" IS NULL)
									THEN ((- 1 * datediff(day, ((getdate())), T1."PURCH_DATE")))
								ELSE ((- 1 * datediff(day, ((getdate())), T1."RECEPTION_DATE")))
								END
							) BETWEEN 181 AND 360
						)
					THEN ('181 - 360 Tage')
				WHEN (
						(
							CASE 
								WHEN (T1."ECC_STATUS" IN ('21', '25'))
									THEN (0)
								WHEN (T1."RECEPTION_DATE" IS NULL)
									THEN ((- 1 * datediff(day, ((getdate())), T1."PURCH_DATE")))
								ELSE ((- 1 * datediff(day, ((getdate())), T1."RECEPTION_DATE")))
								END
							) > 360
						)
					THEN ('> 360 Tage')
				ELSE NULL
				END AS "Standtagestaffel",
			CASE 
				WHEN (T1."ECC_STATUS" IN ('21', '25'))
					THEN (0)
				WHEN (T1."RECEPTION_DATE" IS NULL)
					THEN ((- 1 * datediff(day, ((getdate())), T1."PURCH_DATE")))
				ELSE ((- 1 * datediff(day, ((getdate())), T1."RECEPTION_DATE")))
				END AS "Standtage",
			T1."PURCH_PRICE_UNIT" + T1."COST_UNIT" AS "Einsatz",
			T7."DESCRIPTION" AS "Fabrikat_ori",
			T7."GLOBAL_MAKE_CD" AS "Global Make Cd",
			CASE 
				WHEN (T2."VEHICLE_TYPE" IS NULL)
					THEN (T1."VEHICLE_TYPE")
				ELSE (T2."VEHICLE_TYPE" + ' - ' + T2."VEHICLE_TYPE_TEXT")
				END AS "Fahrzeugtyp",
			(rtrim(T1."UNIT_NUMBER")) + ' - ' + T3."CHASSIS_NUMBER" + ' - ' + (
				CASE 
					WHEN (T2."VEHICLE_TYPE" IS NULL)
						THEN (T1."VEHICLE_TYPE")
					ELSE (T2."VEHICLE_TYPE" + ' - ' + T2."VEHICLE_TYPE_TEXT")
					END
				) AS "FZG",
			T3."COLOUR_CODE" + ' - ' + T3."COLOUR_CF" AS "Farbe",
			T3."CHASSIS_NUMBER" AS "Chassis Number",
			CASE 
				WHEN (T2."VEHICLE_TYPE" IN ('M', 'N', 'T', 'V', 'B'))
					THEN ('Neuwagen')
				WHEN (T2."VEHICLE_TYPE" IN ('D', 'G', 'K', 'R'))
					THEN ('Gebrauchtwagen')
				ELSE NULL
				END AS "Fahrzeugart",
			T6."DESCRIPTION" AS "Description_2",
			T6."DEPARTMENT_TYPE_ID" AS "Department Type Id",
			(left(T6."DEPARTMENT_TYPE_ID", 2)) AS "Standort",
			T1."CLIENT_DB" AS "Hauptbetrieb",
			T5."MAKE_CODE" AS "Make Code",
			T5."MODEL_GROUP" AS "Model Group",
			T5."MODEL_TYPE" AS "Model Type",
			T5."ORIG_MODEL_CODE" AS "Orig Model Code",
			T5."MODEL_TEXT" AS "Model Text",
			T5."MAKE_CD" AS "Make Cd",
			T5."WORKSHOP_MODEL" AS "Workshop Model",
			T4."MAKE_CD" AS "Make Cd_2",
			T4."MODEL_LINE" AS "Model Line",
			T3."MAKE_CD" AS "Make Cd_3",
			T3."SOLDMARK_DATE" AS "Soldmark Date",
			T3."DISCOUNT_PERC_WORK" AS "Discount Perc Work",
			T3."WORKSHOP_PRICECODE" AS "Workshop Pricecode",
			T3."HOURLY_REPAIR_RATE" AS "Hourly Repair Rate",
			T3."SERVICE_DAYS" AS "Service Days",
			T3."FUELTYPE" AS "Fueltype",
			T3."DEALER_MARKING" AS "Dealer Marking",
			T3."DEALER_NUMBER" AS "Dealer Number",
			T3."PURCH_AMOUNT" AS "Purch Amount",
			T3."LATEST_INV_DATE" AS "Latest Inv Date",
			T3."PAID_DATE" AS "Paid Date",
			T3."HOUR_RATE_TABLE" AS "Hour Rate Table",
			T3."MAKE" AS "Make",
			T3."MODEL_TYPE_2" AS "Model Type 2",
			T3."MODEL_LINE_GROUP" AS "Model Line Group",
			T3."PURCH_CAL_DATE" AS "Purch Cal Date",
			T3."STOCK_DATE" AS "Stock Date",
			T3."CAL_COST_DATE" AS "Cal Cost Date",
			T3."CAL_COST" AS "Cal Cost",
			T3."AVAILABLE" AS "Available",
			T3."TYPE_YEAR" AS "Type Year",
			T3."ASU_INSP" AS "Asu Insp",
			T3."ASU_DATE" AS "Asu Date",
			T3."ASU_TYPE" AS "Asu Type",
			T3."TUV_INSP" AS "Tuv Insp",
			T3."TUV_DATE" AS "Tuv Date",
			T3."TUV_TYPE" AS "Tuv Type",
			T3."NO_OF_OWNERS" AS "No Of Owners",
			T3."TRIM_CODE" AS "Trim Code",
			T3."COLOUR_CODE" AS "Colour Code",
			T3."DRIVE_CODE" AS "Drive Code",
			T3."GEAR_CODE" AS "Gear Code",
			T3."MOTOR_CODE" AS "Motor Code",
			T3."MISC_10_CF" AS "Misc 10 Cf",
			T3."MISC_9_CF" AS "Misc 9 Cf",
			T3."MISC_8_CF" AS "Misc 8 Cf",
			T3."MISC_7_CF" AS "Misc 7 Cf",
			T3."MISC_6_CF" AS "Misc 6 Cf",
			T3."MISC_5_CF" AS "Misc 5 Cf",
			T3."MISC_4_CF" AS "Misc 4 Cf",
			T3."MISC_3_CF" AS "Misc 3 Cf",
			T3."MISC_2_CF" AS "Misc 2 Cf",
			T3."MISC_1_CF" AS "Misc 1 Cf",
			T3."MILEAGE" AS "Mileage",
			T3."EQUIPMENT_4" AS "Equipment 4",
			T3."EQUIPMENT_3" AS "Equipment 3",
			T3."EQUIPMENT_2" AS "Equipment 2",
			T3."EQUIPMENT_1" AS "Equipment 1",
			T3."DECLARATION_NUMBER" AS "Declaration Number",
			T3."DECLARATION_PLACE" AS "Declaration Place",
			T3."DECLARATION_DATE" AS "Declaration Date",
			T3."SEATS" AS "Seats",
			T3."CYLINDER_VOLUME" AS "Cylinder Volume",
			T3."YEAR_MODEL_CF" AS "Year Model Cf",
			T3."KEY_CODE" AS "Key Code",
			T3."MOTOR_NUMBER" AS "Motor Number",
			T3."CLASSIFICATION" AS "Classification",
			T3."FAC_MODEL_CODE_S" AS "Fac Model Code S",
			T3."WORKSHOP_MODEL" AS "Workshop Model_2",
			T3."MODEL_LINE" AS "Model Line_2",
			T3."TRIM_TXT" AS "Trim Txt",
			T3."COLOUR_CF" AS "Colour Cf",
			T3."ORIG_MODEL_CODE2" AS "Orig Model Code2",
			T3."ORIG_MODEL_CODE1" AS "Orig Model Code1",
			T3."SALESMAN_SALE" AS "Salesman Sale",
			T3."SALESMAN_BUY" AS "Salesman Buy",
			T3."ARRIVAL_DATE" AS "Arrival Date",
			T3."EXPECTED_ARR_DATE" AS "Expected Arr Date",
			T3."FIRST_OCCUR_DATE" AS "First Occur Date",
			T3."LATEST_REG_DATE" AS "Latest Reg Date",
			T3."FIRST_REG_DATE" AS "First Reg Date",
			T3."FAC_MODEL_CODE_L" AS "Fac Model Code L",
			T3."CAR_STATUS" AS "Car Status",
			T3."CAR_GROUP" AS "Car Group",
			T3."REGISTER_NUMBER" AS "Register Number",
			T3."HANDLER" AS "Handler",
			T3."TRANSACT_DATE" AS "Transact Date",
			T3."BASIS_NUMBER" AS "Basis Number",
			CASE 
				WHEN (T1."ECC_STATUS" = '21')
					THEN ('21 - Lagerauftrag')
				WHEN (T1."ECC_STATUS" = '25')
					THEN ('25 - Kundenauftrag')
				WHEN (T1."ECC_STATUS" = '41')
					THEN ('41 - Bestand')
				WHEN (T1."ECC_STATUS" = '44')
					THEN ('44 - auf Lager verkauft')
				WHEN (T1."ECC_STATUS" = '64')
					THEN ('64 - verkauft')
				WHEN (T1."ECC_STATUS" = '42')
					THEN ('42')
				ELSE NULL
				END AS "ECC_Status_Text",
			T2."VEHICLE_TYPE_TEXT" AS "Vehicle Type Text",
			T2."VEHICLE_TYPE" AS "Vehicle Type",
			T1."UNIQUE_IDENT" AS "Unique Ident",
			T1."PRICE_LIST_DATE" AS "Price List Date",
			T1."PRICE_LIST_VERSION" AS "Price List Version",
			T1."PURCH_ORIGIN_CODE" AS "Purch Origin Code",
			T1."SALE_PRICE_DATE" AS "Sale Price Date",
			T1."BUD_OPT_PRICE" AS "Bud Opt Price",
			T1."RECEPTION_DATE" AS "Reception Date",
			T1."EST_REFERENCE_NO" AS "Est Reference No",
			T1."EST_SALES_PRICE" AS "Est Sales Price",
			T1."FORD_INT_DATE" AS "Ford Int Date",
			T1."VALUATION_DATE" AS "Valuation Date",
			T1."DESIRED_DELIV_DATE" AS "Desired Deliv Date",
			T1."BOOKING_DEALER_NR" AS "Booking Dealer Nr",
			T1."DEALER_MARKING" AS "Dealer Marking_2",
			T1."EXP_ARRIVAL_TIME" AS "Exp Arrival Time",
			T1."CONTRACT_DATE" AS "Contract Date",
			T1."CNTRACT_DUE_DATE" AS "Cntract Due Date",
			T1."TRANSFER_VAT_RC" AS "Transfer Vat Rc",
			T1."VAT_RATE_CODE" AS "Vat Rate Code",
			T1."VAT_TABLE_NORMAL" AS "Vat Table Normal",
			T1."VAT_TABLE_WORK" AS "Vat Table Work",
			T1."PRICE_LABEL_DATE" AS "Price Label Date",
			T1."ORDER_CONFIRM_DATE" AS "Order Confirm Date",
			T1."ORDER_ARRIVAL_DATE" AS "Order Arrival Date",
			T1."TRF_DEPARTMENT" AS "Trf Department",
			T1."UNIT_SOLD" AS "Unit Sold",
			T1."SALE_ORDER_NO" AS "Sale Order No",
			T1."TRF_TAXBASIS_PURCH" AS "Trf Taxbasis Purch",
			T1."TRF_TAXBASIS_SALES" AS "Trf Taxbasis Sales",
			T1."FREIGHT_BALANCE" AS "Freight Balance",
			T1."RESERVATION_TEXT" AS "Reservation Text",
			T1."RESERVATION_PERSON" AS "Reservation Person",
			T1."RESERVATION_DATE" AS "Reservation Date",
			T1."DELIVERY_DATE_VEH" AS "Delivery Date Veh",
			T1."COMMISION_NO" AS "Commision No",
			T1."RECALC_CODE" AS "Recalc Code",
			T1."BUDG_PRICE_VAT" AS "Budg Price Vat",
			T1."ACCOUNT_SALES" AS "Account Sales",
			T1."ACCOUNT_PURCHASE" AS "Account Purchase",
			T1."INVOICE_PERMISSION" AS "Invoice Permission",
			T1."LATEST_UPDATE" AS "Latest Update",
			T1."VEHICLE_UPDATE" AS "Vehicle Update",
			T1."PA_NUMBER" AS "Pa Number",
			T1."BUYING_ORDER_DATE" AS "Buying Order Date",
			T1."BUYING_ORDER_NO" AS "Buying Order No",
			T1."CONDITION_UNIT" AS "Condition Unit",
			T1."TRANSFER_BBDB" AS "Transfer Bbdb",
			T1."DELETE_PROPOSAL" AS "Delete Proposal",
			T1."STOCK_DAYS" AS "Stock Days",
			T1."TRANSFER_DATE" AS "Transfer Date",
			T1."OR_MARK" AS "Or Mark",
			T1."COST_TAX" AS "Cost Tax",
			T1."PURCH_TAX" AS "Purch Tax",
			T1."TRANSFER_SOLD" AS "Transfer Sold",
			T1."TRANSFER_TAX_PCT" AS "Transfer Tax Pct",
			T1."TRANSFER_TAX_BASIS" AS "Transfer Tax Basis",
			T1."TRANSFER_ACC_CODE" AS "Transfer Acc Code",
			T1."TRANSFER_TAX_HAND" AS "Transfer Tax Hand",
			T1."TRANSFER_LINE" AS "Transfer Line",
			T1."NEXT_LINE_1" AS "Next Line 1",
			T1."NEXT_LINE_UNIT" AS "Next Line Unit",
			T1."INTEREST_2" AS "Interest 2",
			T1."INTEREST_1" AS "Interest 1",
			T1."REG_FEE" AS "Reg Fee",
			T1."SALES_PRICE_UNIT" AS "Sales Price Unit",
			T1."PURCH_PRICE_UNIT" AS "Purch Price Unit",
			T1."OWNER" AS "Owner",
			T1."BUD_DEDUCT_FEE" AS "Bud Deduct Fee",
			T1."BUD_REG_FEE" AS "Bud Reg Fee",
			T1."BUD_PURCH_PRICE" AS "Bud Purch Price",
			T1."UNIT_IN_CHANGE" AS "Unit In Change",
			T1."SCRAP_CODE" AS "Scrap Code",
			T1."SALE_DATE" AS "Sale Date",
			T1."SALE_INV_NUMBER" AS "Sale Inv Number",
			T1."SALE_SALESMAN" AS "Sale Salesman",
			T1."SALES_DEPARTMENT" AS "Sales Department",
			T1."PURCH_DATE" AS "Purch Date",
			T1."PURCH_INVNO" AS "Purch Invno",
			T1."PURCH_SALSMAN_CODE" AS "Purch Salsman Code",
			T1."PURCH_DEPARTMENT" AS "Purch Department",
			T1."INTEREST_CODE" AS "Interest Code",
			T1."TAX_HANDLING" AS "Tax Handling",
			T1."BOOK_KEEPING_CODE" AS "Book Keeping Code",
			T1."TRANSFER_TAX" AS "Transfer Tax",
			T1."DEPRECIATION" AS "Depreciation",
			T1."UNIT_LAST_UPD_DTE" AS "Unit Last Upd Dte",
			T1."TAX_CODE" AS "Tax Code",
			T1."INTERNAL_CODE" AS "Internal Code",
			T1."DISCOUNT_LIMIT" AS "Discount Limit",
			T1."DISCOUNT_PERC_WORK" AS "Discount Perc Work_2",
			T1."PRICE_CODE" AS "Price Code",
			T1."DELIVERY_STOP_CODE" AS "Delivery Stop Code",
			T1."SMALL_INV_CHARGE" AS "Small Inv Charge",
			T1."SMALL_ACCESSORIES" AS "Small Accessories",
			T1."PMT_TERM" AS "Pmt Term",
			T1."CAR_CREATION_DATE" AS "Car Creation Date",
			T1."HANDLER" AS "Handler_2",
			T1."TRANSACT_DATE" AS "Transact Date_2",
			T1."VEHICLE_TYPE" AS "Vehicle Type_2",
			T1."ECC_STATUS" AS "Ecc Status",
			T1."BASIS_NUMBER" AS "Basis Number_2"
		FROM (
			(
				(
					(
						(
							(
								(
									(
										(
											(
												"OPTIMA"."import"."UNIT_FILE" T1 LEFT JOIN "OPTIMA"."import"."vPP5R" T2 ON (T1."VEHICLE_TYPE" = T2."VEHICLE_TYPE")
													AND (T1."CLIENT_DB" = T2."CLIENT_DB")
												) LEFT JOIN "OPTIMA"."import"."VEHICLE" T3 ON T1."BASIS_NUMBER" = T3."BASIS_NUMBER"
											) LEFT JOIN "OPTIMA"."import"."VPP5Q" T4 ON (
												(T3."MODEL_LINE" = T4."MODEL_LINE")
												AND (T3."MAKE_CD" = T4."MAKE_CD")
												)
											AND (T3."CLIENT_DB" = T4."CLIENT_DB")
										) LEFT JOIN "OPTIMA"."import"."vPP74" T5 ON (
											(T3."WORKSHOP_MODEL" = T5."WORKSHOP_MODEL")
											AND (T3."MAKE_CD" = T5."MAKE_CD")
											)
										AND (T3."CLIENT_DB" = T5."CLIENT_DB")
									) LEFT JOIN "OPTIMA"."import"."DEPARTMENT_TYPE" T6 ON (T1."PURCH_DEPARTMENT" = T6."DEPARTMENT_TYPE_ID")
									AND (T1."CLIENT_DB" = T6."CLIENT_DB")
								) LEFT JOIN "OPTIMA"."import"."GLOBAL_MAKE" T7 ON (T3."MAKE_CD" = T7."GLOBAL_MAKE_CD")
								AND (T3."CLIENT_DB" = T7."CLIENT_DB")
							) LEFT JOIN "OPTIMA"."import"."VPP43" T8 ON (T1."PURCH_SALSMAN_CODE" = T8."SELLER_CODE")
							AND (T1."CLIENT_DB" = T8."CLIENT_DB")
						) LEFT JOIN "OPTIMA"."import"."UNIT_CHANGE_HIST" T9 ON (
							(T9."UNIT_NUMBER" = T1."UNIT_NUMBER")
							AND (T9."DEPARTMENT" <> ' ')
							)
						AND (T1."CLIENT_DB" = T9."CLIENT_DB")
					) LEFT JOIN "OPTIMA"."data"."GC_Department" T10 ON (T1."CLIENT_DB" = T10."Hauptbetrieb")
					AND ((left(T1."PURCH_DEPARTMENT", 1)) = T10."Standort")
				) LEFT JOIN "OPTIMA"."data"."GC_Marken" T11 ON (T3."CLIENT_DB" = T11."Client_DB")
				AND (T3."MAKE_CD" = T11."Make")
			)
		WHERE (T1."ECC_STATUS" IN ('41', '42', '44'))
		) D2
	) D1
WHERE (
		(c260 = "Unique Ident_unique_change_history")
		OR ("Unique Ident_unique_change_history" IS NULL)
		)
	-- order by "Unit Number" asc,"Standtage" desc
