SELECT "No" AS "No",
	"Sell-to Customer No" AS "Sell-to Customer No",
	"Bill-to Customer No" AS "Bill-to Customer No",
	"Bill-to Name" AS "Bill-to Name",
	"Bill-to City" AS "Bill-to City",
	"Posting Date" AS "Posting Date",
	"Location Code" AS "Location Code",
	"Department Code" AS "Department Code",
	"Make Code" AS "Make Code",
	"Salesperson Code" AS "Salesperson Code",
	"Gen Bus Posting Group" AS "Gen Bus Posting Group",
	"Sell-to Customer Name" AS "Sell-to Customer Name",
	"Sell-to City" AS "Sell-to City",
	"Document Date" AS "Document Date",
	"User Id" AS "User Id",
	"Service Order No_ohne_Einschr�nkung" AS "Service Order No_ohne_Einschr�nkung",
	"Branch Code" AS "Branch Code",
	"Vin" AS "Vin",
	"Model Code" AS "Model Code",
	"Model No" AS "Model No",
	"Model_ori" AS "Model_ori",
	"Document No" AS "Document No",
	"Line No" AS "Line No",
	"Type" AS "Type",
	"No_Pos." AS "No_Pos.",
	"Description" AS "Description",
	"Quantity" AS "Quantity",
	"Unit Price" AS "Unit Price",
	"Unit Cost (lcy)" AS "Unit Cost (lcy)",
	"Line Discount Amount" AS "Line Discount Amount",
	"Amount" AS "Amount",
	"Gen Prod Posting Group" AS "Gen Prod Posting Group",
	"Unit Cost" AS "Unit Cost",
	"Order No" AS "Order No",
	"Order Line No" AS "Order Line No",
	"Order Type" AS "Order Type",
	"Item Type" AS "Item Type",
	"Vehicle Status" AS "Vehicle Status",
	"Registration Date" AS "Registration Date",
	"Mileage" AS "Mileage",
	"Service Order No_" AS "Service Order No_",
	"Service Order Line No" AS "Service Order Line No",
	"Labor No" AS "Labor No",
	"Customer Group Code" AS "Customer Group Code",
	"Item Group Code" AS "Item Group Code",
	"Service Advisor No_Archiv" AS "Service Advisor No_Archiv",
	"Service Advisor No_oA" AS "Service Advisor No_oA",
	"No_f�r_Archiv" AS "No_f�r_Archiv",
	"First Name_f�r_Archiv" AS "First Name_f�r_Archiv",
	"Last Name_f�r_Archiv" AS "Last Name_f�r_Archiv",
	"No_SB" AS "No_SB",
	"First Name" AS "First Name",
	"Last Name" AS "Last Name",
	"Serviceberater" AS "Serviceberater",
	"Hauptbetrieb" AS "Hauptbetrieb",
	"Standort" AS "Standort",
	"Umsatzart" AS "Umsatzart",
	"Fabrikat" AS "Fabrikat",
	"Model" AS "Model",
	"Fahrzeug" AS "Fahrzeug",
	"Marke" AS "Marke",
	"Service Posting Group_f�r_Archiv" AS "Service Posting Group_f�r_Archiv",
	"Service Posting Group" AS "Service Posting Group",
	"Auftragsart" AS "Auftragsart",
	"Cust_Gr_Code" AS "Cust_Gr_Code",
	"Cust_Gr_Description" AS "Cust_Gr_Description",
	"Kundenart" AS "Kundenart",
	"Cust_No" AS "Cust_No",
	"Cust_Name" AS "Cust_Name",
	"Kunde" AS "Kunde",
	"Monteur" AS "Monteur",
	"Umsatz Lohn" AS "Umsatz Lohn",
	"Umsatz Teile Service_ori" AS "Umsatz Teile Service_ori",
	"Umsatz Sonstiges_ori" AS "Umsatz Sonstiges_ori",
	"Anzahl Datens�tze" AS "Anzahl Datens�tze",
	"Umsatz Teile Service" AS "Umsatz Teile Service",
	"Umsatz Sonstiges" AS "Umsatz Sonstiges",
	"verk Std" AS "verk Std",
	"ben Zeit" AS "ben Zeit",
	"Invoice Date" AS "Invoice Date",
	"Order Number" AS "Order Number",
	"Order Number_Rg_Ausg" AS "Order Number_Rg_Ausg",
	"DG1" AS "DG1",
	COUNT("Service Order Line No") OVER (PARTITION BY "No") AS "DG2",
	("DG1" / COUNT("Service Order Line No") OVER (PARTITION BY "No")) AS "DG",
	"Order Number_Rg_Ausg_2" AS "Order Number_Rg_Ausg_2",
	"Order Number_Rg_Ausg_1" AS "Order Number_Rg_Ausg_1",
	"Cust_No_Verkaufskunde" AS "Cust_No_Verkaufskunde",
	"Cust_Name_Verkaufskunde" AS "Cust_Name_Verkaufskunde",
	"Cust_Group_Description_Verkaufskunde" AS "Cust_Group_Description_Verkaufskunde",
	"Kundenart_Verkaufskunde" AS "Kundenart_Verkaufskunde",
	"Kunde_Verkaufskunde" AS "Kunde_Verkaufskunde",
	"Auftragsposition" AS "Auftragsposition",
	"Rabatt Lohn" AS "Rabatt Lohn",
	"NL Teile_ori" AS "NL Teile_ori",
	"Rabatt Teile" AS "Rabatt Teile",
	"Hauptbetrieb_ID" AS "Hauptbetrieb_ID",
	"Standort_ID" AS "Standort_ID",
	"NL Lohn %" AS "NL Lohn %",
	"Nachlass > 90 %" AS "Nachlass > 90 %",
	"NL Teile %" AS "NL Teile %",
	"Zuordnung_Funktion" AS "Zuordnung_Funktion",
	"Order_Desc_30" AS "Order_Desc_30",
	"Invoice_Desc_30" AS "Invoice_Desc_30",
	"Model_Desc" AS "Model_Desc",
	"Fahrgestellnummer" AS "Fahrgestellnummer",
	"Fahrzeugalter_Tage" AS "Fahrzeugalter_Tage",
	"Customer_Group_Owner" AS "Customer_Group_Owner",
	"Customer_Name_Owner" AS "Customer_Name_Owner",
	"Fahrzeugalter" AS "Fahrzeugalter",
	"FZG-Altersstaffel" AS "FZG-Altersstaffel",
	"Rechnung_Gutschrift" AS "Rechnung_Gutschrift",
	"Parts_Focus_Group" AS "Parts_Focus_Group",
	"Parts_Make_Desc" AS "Parts_Make_Desc",
	"Parts_Group_Desc" AS "Parts_Group_Desc",
	"Post Code" AS "Post Code",
	"PLZ_1_Stelle" AS "PLZ_1_Stelle",
	"PLZ_2_Stelle" AS "PLZ_2_Stelle",
	"PLZ_3_Stelle" AS "PLZ_3_Stelle",
	"PLZ_4_Stelle" AS "PLZ_4_Stelle",
	"PLZ" AS "PLZ",
	"Order_Desc_100" AS "Order_Desc_100",
	"Invoice_Desc_100" AS "Invoice_Desc_100",
	"Produktbuchungsgruppe" AS "Produktbuchungsgruppe",
	"T�V_Amount" AS "T�V_Amount",
	"FL_Lack_Amount" AS "FL_Lack_Amount",
	"Mietw_Amount" AS "Mietw_Amount",
	"Umsatz_Sonst_Rest" AS "Umsatz_Sonst_Rest",
	"Service Order No_30" AS "Service Order No_30",
	"Service_Order_No_Teile_Order_No" AS "Service_Order_No_Teile_Order_No",
	"Code_Salesperson" AS "Code_Salesperson",
	"Name_Salesperson" AS "Name_Salesperson",
	"Serviceberater_Service" AS "Serviceberater_Service",
	"Tage bis Rechnung" AS "Tage bis Rechnung",
	"Einsatz Teile Service" AS "Einsatz Teile Service",
	"Order No_" AS "Order No_",
	"Auftragsnr." AS "Auftragsnr.",
	"RG/Auftrag/Kunde" AS "RG/Auftrag/Kunde",
	"RG/SB/Kunde/Datum" AS "RG/SB/Kunde/Datum",
	"Monat" AS "Monat",
	"Jahr" AS "Jahr",
	"Artikel / AW-Nr" AS "Artikel / AW-Nr",
	"EW Fremdl." AS "EW Fremdl.",
	"DB 1 Fremdl." AS "DB 1 Fremdl.",
	"DB 1 Fremdl. %" AS "DB 1 Fremdl. %"
FROM (
	SELECT "No",
		"Sell-to Customer No",
		"Bill-to Customer No",
		"Bill-to Name",
		"Bill-to City",
		"Posting Date",
		"Location Code",
		"Department Code",
		"Make Code",
		"Salesperson Code",
		"Gen Bus Posting Group",
		"Sell-to Customer Name",
		"Sell-to City",
		"Document Date",
		"User Id",
		"Service Order No_ohne_Einschr�nkung",
		"Branch Code",
		"Vin",
		'' AS "Model Code",
		'' AS "Model No",
		"Model_ori",
		"Document No",
		"Line No",
		"Type",
		"No_Pos.",
		"Description",
		"Quantity",
		"Unit Price",
		"Unit Cost (lcy)" AS "Unit Cost (lcy)",
		"Line Discount Amount",
		"Amount",
		"Gen Prod Posting Group",
		"Unit Cost",
		"Order No",
		"Order Line No",
		"Order Type",
		"Item Type",
		"Vehicle Status",
		"Registration Date",
		"Mileage",
		"Service Order No_",
		"Service Order Line No",
		"Labor No",
		"Customer Group Code",
		"Item Group Code",
		"Service Advisor No_Archiv",
		"Service Advisor No_oA",
		"No_f�r_Archiv",
		"First Name_f�r_Archiv",
		"Last Name_f�r_Archiv",
		"No_SB",
		"First Name",
		"Last Name",
		"Serviceberater",
		'1' AS "Hauptbetrieb",
		"Standort",
		"Umsatzart",
		"Fabrikat",
		"Model_ori" AS "Model",
		"Fahrzeug",
		"Marke",
		"Service Posting Group_f�r_Archiv",
		"Service Posting Group",
		"Auftragsart",
		"Cust_Gr_Code",
		"Cust_Gr_Description",
		"Kundenart",
		"Cust_No",
		"Cust_Name",
		"Kunde",
		'' AS "Monteur",
		"Umsatz Lohn",
		"Umsatz Teile Service_ori",
		"Umsatz Sonstiges_ori",
		COUNT("No") OVER (PARTITION BY c152) AS "Anzahl Datens�tze",
		("Umsatz Teile Service_ori") / (COUNT("No") OVER (PARTITION BY c152)) AS "Umsatz Teile Service",
		("Umsatz Sonstiges_ori") / (COUNT("No") OVER (PARTITION BY c152)) AS "Umsatz Sonstiges",
		"verk Std",
		0 AS "ben Zeit",
		"Posting Date" AS "Invoice Date",
		"Order Number",
		"Order Number_Rg_Ausg",
		- 1 AS "DG1",
		"Order Number_Rg_Ausg_2",
		"Order Number_Rg_Ausg_1",
		"Cust_No_Verkaufskunde",
		"Cust_Name_Verkaufskunde",
		"Cust_Group_Description_Verkaufskunde",
		"Kundenart_Verkaufskunde",
		"Kunde_Verkaufskunde",
		"Auftragsposition",
		"Rabatt Lohn",
		"NL Teile_ori",
		("NL Teile_ori") / (COUNT("No") OVER (PARTITION BY c152)) AS "Rabatt Teile",
		'1' AS "Hauptbetrieb_ID",
		"Standort" AS "Standort_ID",
		"NL Lohn %",
		CASE 
			WHEN (
					(
						(("NL Lohn %") > 90)
						AND (("Rabatt Lohn") <> 0)
						)
					AND (c186 <> 1)
					)
				THEN ('Nachlass > 90 %')
			WHEN (
					(
						(
							(
								CASE 
									WHEN (((("Umsatz Teile Service_ori") / (COUNT("No") OVER (PARTITION BY c152))) + (("NL Teile_ori") / (COUNT("No") OVER (PARTITION BY c152)))) <> 0)
										THEN ((("NL Teile_ori") / (COUNT("No") OVER (PARTITION BY c152))) / ((("Umsatz Teile Service_ori") / (COUNT("No") OVER (PARTITION BY c152))) + (("NL Teile_ori") / (COUNT("No") OVER (PARTITION BY c152)))) * 100
												)
									ELSE (0)
									END
								) > 90
							)
						AND ((("NL Teile_ori") / (COUNT("No") OVER (PARTITION BY c152))) <> 0)
						)
					AND (c186 <> 1)
					)
				THEN ('Nachlass > 90 %')
			ELSE ('Nachlass < 90 %')
			END AS "Nachlass > 90 %",
		CASE 
			WHEN (((("Umsatz Teile Service_ori") / (COUNT("No") OVER (PARTITION BY c152))) + (("NL Teile_ori") / (COUNT("No") OVER (PARTITION BY c152)))) <> 0)
				THEN ((("NL Teile_ori") / (COUNT("No") OVER (PARTITION BY c152))) / ((("Umsatz Teile Service_ori") / (COUNT("No") OVER (PARTITION BY c152))) + (("NL Teile_ori") / (COUNT("No") OVER (PARTITION BY c152)))) * 100)
			ELSE (0)
			END AS "NL Teile %",
		'Serviceberater' AS "Zuordnung_Funktion",
		"Order_Desc_30",
		"Invoice_Desc_30",
		"Model_ori" AS "Model_Desc",
		"Vin" AS "Fahrgestellnummer",
		"Fahrzeugalter_Tage",
		"Gen Bus Posting Group" AS "Customer_Group_Owner",
		"Cust_Name" AS "Customer_Name_Owner",
		"Fahrzeugalter",
		"FZG-Altersstaffel",
		'Gutschrift' AS "Rechnung_Gutschrift",
		'' AS "Parts_Focus_Group",
		'' AS "Parts_Make_Desc",
		'' AS "Parts_Group_Desc",
		"Post Code",
		"PLZ_1_Stelle",
		"PLZ_2_Stelle",
		"PLZ_3_Stelle",
		"PLZ_4_Stelle",
		"Post Code" AS "PLZ",
		"Order_Desc_100",
		"Invoice_Desc_100",
		"Gen Prod Posting Group" AS "Produktbuchungsgruppe",
		CASE 
			WHEN ("Gen Prod Posting Group" IN ('816_SONST', '817_SONST'))
				THEN ((("Umsatz Sonstiges_ori") / (COUNT("No") OVER (PARTITION BY c152))))
			ELSE (0)
			END AS "T�V_Amount",
		CASE 
			WHEN ("Gen Prod Posting Group" IN ('821_SONST', '823_SONST', '828_SONST'))
				THEN ((("Umsatz Sonstiges_ori") / (COUNT("No") OVER (PARTITION BY c152))))
			ELSE (0)
			END AS "FL_Lack_Amount",
		CASE 
			WHEN ("Gen Prod Posting Group" IN ('881_SONST', '886_SONST'))
				THEN ((("Umsatz Sonstiges_ori") / (COUNT("No") OVER (PARTITION BY c152))))
			ELSE (0)
			END AS "Mietw_Amount",
		(("Umsatz Sonstiges_ori") / (COUNT("No") OVER (PARTITION BY c152))) - (
			CASE 
				WHEN ("Gen Prod Posting Group" IN ('816_SONST', '817_SONST'))
					THEN ((("Umsatz Sonstiges_ori") / (COUNT("No") OVER (PARTITION BY c152))))
				ELSE (0)
				END
			) - (
			CASE 
				WHEN ("Gen Prod Posting Group" IN ('821_SONST', '823_SONST', '828_SONST'))
					THEN ((("Umsatz Sonstiges_ori") / (COUNT("No") OVER (PARTITION BY c152))))
				ELSE (0)
				END
			) - (
			CASE 
				WHEN ("Gen Prod Posting Group" IN ('881_SONST', '886_SONST'))
					THEN ((("Umsatz Sonstiges_ori") / (COUNT("No") OVER (PARTITION BY c152))))
				ELSE (0)
				END
			) AS "Umsatz_Sonst_Rest",
		"Order_Desc_30" AS "Service Order No_30",
		"Service_Order_No_Teile_Order_No",
		"Code_Salesperson",
		"Name_Salesperson",
		"Serviceberater_Service",
		'0' AS "Tage bis Rechnung",
		CASE 
			WHEN ("Gen Prod Posting Group" LIKE '%ART%')
				THEN ((c155) / (COUNT("No") OVER (PARTITION BY c152)) * - 1)
			ELSE (0)
			END AS "Einsatz Teile Service",
		"Order No_",
		"Service_Order_No_Teile_Order_No" AS "Auftragsnr.",
		"RG/Auftrag/Kunde",
		"RG/SB/Kunde/Datum",
		"Monat",
		"Jahr",
		"Artikel / AW-Nr",
		CASE 
			WHEN ("Gen Prod Posting Group" IN ('821_SONST', '823_SONST', '828_SONST', '822_SONST', '824_SONST', '825_SONST', '826_SONST', '827_SONST', '829_SONST'))
				THEN ((c155) / (COUNT("No") OVER (PARTITION BY c152)) * - 1)
			ELSE (0)
			END AS "EW Fremdl.",
		(
			CASE 
				WHEN ("Gen Prod Posting Group" IN ('821_SONST', '823_SONST', '828_SONST'))
					THEN ((("Umsatz Sonstiges_ori") / (COUNT("No") OVER (PARTITION BY c152))))
				ELSE (0)
				END
			) - (
			CASE 
				WHEN ("Gen Prod Posting Group" IN ('821_SONST', '823_SONST', '828_SONST', '822_SONST', '824_SONST', '825_SONST', '826_SONST', '827_SONST', '829_SONST'))
					THEN ((c155) / (COUNT("No") OVER (PARTITION BY c152)) * - 1)
				ELSE (0)
				END
			) AS "DB 1 Fremdl.",
		CASE 
			WHEN (
					(
						CASE 
							WHEN ("Gen Prod Posting Group" IN ('821_SONST', '823_SONST', '828_SONST'))
								THEN ((("Umsatz Sonstiges_ori") / (COUNT("No") OVER (PARTITION BY c152))))
							ELSE (0)
							END
						) <> 0
					)
				THEN (
						(
							(
								CASE 
									WHEN ("Gen Prod Posting Group" IN ('821_SONST', '823_SONST', '828_SONST'))
										THEN ((("Umsatz Sonstiges_ori") / (COUNT("No") OVER (PARTITION BY c152))))
									ELSE (0)
									END
								) - (
								CASE 
									WHEN ("Gen Prod Posting Group" IN ('821_SONST', '823_SONST', '828_SONST', '822_SONST', '824_SONST', '825_SONST', '826_SONST', '827_SONST', '829_SONST'))
										THEN ((c155) / (COUNT("No") OVER (PARTITION BY c152)) * - 1)
									ELSE (0)
									END
								)
							) / (
							CASE 
								WHEN ("Gen Prod Posting Group" IN ('821_SONST', '823_SONST', '828_SONST'))
									THEN ((("Umsatz Sonstiges_ori") / (COUNT("No") OVER (PARTITION BY c152))))
								ELSE (0)
								END
							) * 100
						)
			ELSE (0)
			END AS "DB 1 Fremdl. %"
	FROM (
		SELECT T1."No_" AS "No",
			(T2."Document No_" + (((T2."Line No_")))) AS c152,
			T2."Gen_ Prod_ Posting Group" AS "Gen Prod Posting Group",
			CASE 
				WHEN (
						(T2."Gen_ Prod_ Posting Group" LIKE '%FZG%')
						OR (T2."Gen_ Prod_ Posting Group" LIKE '%SONST%')
						)
					THEN (((convert(FLOAT, T2."Amount"))) * - 1)
				ELSE (0)
				END AS "Umsatz Sonstiges_ori",
			((convert(FLOAT, T2."Quantity"))) * T2."Unit Cost (LCY)" AS c155,
			T2."No_" + ' - ' + T2."Description" AS "Artikel / AW-Nr",
			(year(T1."Posting Date")) AS "Jahr",
			(month(T1."Posting Date")) AS "Monat",
			CASE 
				WHEN (
						(
							CASE 
								WHEN (
										(
											(
												CASE 
													WHEN (
															(
																(T1."No_" LIKE 'W%')
																OR (T1."No_" LIKE '%I%')
																)
															)
														THEN ('Service')
													WHEN (
															((left(T1."No_", 2)) IN ('VG'))
															AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
															)
														THEN ('Teile')
													ELSE NULL
													END
												) = 'Service'
											)
										AND (
											(
												CASE 
													WHEN (T6."No_" IS NULL)
														THEN (T7."First Name" + ' ' + T7."Last Name")
													ELSE (T6."First Name" + ' ' + T6."Last Name")
													END
												) <> ' '
											)
										)
									THEN (
											(
												CASE 
													WHEN (T6."No_" IS NULL)
														THEN (T7."First Name" + ' ' + T7."Last Name")
													ELSE (T6."First Name" + ' ' + T6."Last Name")
													END
												)
											)
								WHEN (
										(
											(
												CASE 
													WHEN (
															(
																(T1."No_" LIKE 'W%')
																OR (T1."No_" LIKE '%I%')
																)
															)
														THEN ('Service')
													WHEN (
															((left(T1."No_", 2)) IN ('VG'))
															AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
															)
														THEN ('Teile')
													ELSE NULL
													END
												) = 'Teile'
											)
										AND (T8."Name" IS NOT NULL)
										)
									THEN (T8."Name")
								ELSE ('n.N.')
								END
							) IS NOT NULL
						)
					THEN (
							T1."No_" + ' - ' + (
								CASE 
									WHEN (
											(
												(
													CASE 
														WHEN (
																(
																	(T1."No_" LIKE 'W%')
																	OR (T1."No_" LIKE '%I%')
																	)
																)
															THEN ('Service')
														WHEN (
																((left(T1."No_", 2)) IN ('VG'))
																AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																)
															THEN ('Teile')
														ELSE NULL
														END
													) = 'Service'
												)
											AND (
												(
													CASE 
														WHEN (T6."No_" IS NULL)
															THEN (T7."First Name" + ' ' + T7."Last Name")
														ELSE (T6."First Name" + ' ' + T6."Last Name")
														END
													) <> ' '
												)
											)
										THEN (
												(
													CASE 
														WHEN (T6."No_" IS NULL)
															THEN (T7."First Name" + ' ' + T7."Last Name")
														ELSE (T6."First Name" + ' ' + T6."Last Name")
														END
													)
												)
									WHEN (
											(
												(
													CASE 
														WHEN (
																(
																	(T1."No_" LIKE 'W%')
																	OR (T1."No_" LIKE '%I%')
																	)
																)
															THEN ('Service')
														WHEN (
																((left(T1."No_", 2)) IN ('VG'))
																AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																)
															THEN ('Teile')
														ELSE NULL
														END
													) = 'Teile'
												)
											AND (T8."Name" IS NOT NULL)
											)
										THEN (T8."Name")
									ELSE ('n.N.')
									END
								) + ' - ' + T10."Name" + ' - ' + (convert(VARCHAR(50), year(T1."Posting Date")) + '-' + convert(VARCHAR(50), month(T1."Posting Date")) + '-' + convert(VARCHAR(50), day(T1."Posting Date")))
							)
				WHEN (
						(
							CASE 
								WHEN (
										(
											(
												CASE 
													WHEN (
															(
																(T1."No_" LIKE 'W%')
																OR (T1."No_" LIKE '%I%')
																)
															)
														THEN ('Service')
													WHEN (
															((left(T1."No_")) IN ('VG'))
															AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
															)
														THEN ('Teile')
													ELSE NULL
													END
												) = 'Service'
											)
										AND (
											(
												CASE 
													WHEN (T6."No_" IS NULL)
														THEN (T7."First Name" + ' ' + T7."Last Name")
													ELSE (T6."First Name" + ' ' + T6."Last Name")
													END
												) <> ' '
											)
										)
									THEN (
											(
												CASE 
													WHEN (T6."No_" IS NULL)
														THEN (T7."First Name" + ' ' + T7."Last Name")
													ELSE (T6."First Name" + ' ' + T6."Last Name")
													END
												)
											)
								WHEN (
										(
											(
												CASE 
													WHEN (
															(
																(T1."No_" LIKE 'W%')
																OR (T1."No_" LIKE '%I%')
																)
															)
														THEN ('Service')
													WHEN (
															((left(T1."No_", 2)) IN ('VG'))
															AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
															)
														THEN ('Teile')
													ELSE NULL
													END
												) = 'Teile'
											)
										AND (T8."Name" IS NOT NULL)
										)
									THEN (T8."Name")
								ELSE ('n.N.')
								END
							) IS NULL
						)
					THEN (T1."No_" + ' - ' + 'SB fehlt' + ' - ' + T10."Name" + ' - ' + (convert(VARCHAR(50), year(T1."Posting Date")) + '-' + convert(VARCHAR(50), month(T1."Posting Date")) + '-' + convert(VARCHAR(50), day(T1."Posting Date"))))
				ELSE NULL
				END AS "RG/SB/Kunde/Datum",
			T1."No_" + ' - ' + (
				(
					CASE 
						WHEN (
								(
									CASE 
										WHEN (
												(
													(T1."No_" LIKE 'W%')
													OR (T1."No_" LIKE '%I%')
													)
												)
											THEN ('Service')
										WHEN (
												((left(T1."No_", 2)) IN ('VG'))
												AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
												)
											THEN ('Teile')
										ELSE NULL
										END
									) = 'Service'
								)
							THEN (
									(
										CASE 
											WHEN (T2."Service Order No_" IS NULL)
												THEN ('Gutschrift ohne Auftrag')
											ELSE (T2."Service Order No_")
											END
										)
									)
						WHEN (
								(
									CASE 
										WHEN (
												(
													(T1."No_" LIKE 'W%')
													OR (T1."No_" LIKE '%I%')
													)
												)
											THEN ('Service')
										WHEN (
												((left(T1."No_", 2)) IN ('VG'))
												AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
												)
											THEN ('Teile')
										ELSE NULL
										END
									) = 'Teile'
								)
							THEN (
									(
										CASE 
											WHEN (
													(
														(
															CASE 
																WHEN (
																		(
																			(T1."No_" LIKE 'W%')
																			OR (T1."No_" LIKE '%I%')
																			)
																		)
																	THEN ('Service')
																WHEN (
																		((left(T1."No_", 2)) IN ('VG'))
																		AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																		)
																	THEN ('Teile')
																ELSE NULL
																END
															) = 'Teile'
														)
													AND (T2."Order No_" = '')
													)
												THEN ('Gutschrift ohne Auftrag')
											ELSE (T2."Order No_")
											END
										)
									)
						ELSE NULL
						END
					)
				) + ' - ' + T10."Name" AS "RG/Auftrag/Kunde",
			(
				CASE 
					WHEN (
							(
								CASE 
									WHEN (
											(
												(T1."No_" LIKE 'W%')
												OR (T1."No_" LIKE '%I%')
												)
											)
										THEN ('Service')
									WHEN (
											((left(T1."No_", 2)) IN ('VG'))
											AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
											)
										THEN ('Teile')
									ELSE NULL
									END
								) = 'Service'
							)
						THEN (
								(
									CASE 
										WHEN (T2."Service Order No_" IS NULL)
											THEN ('Gutschrift ohne Auftrag')
										ELSE (T2."Service Order No_")
										END
									)
								)
					WHEN (
							(
								CASE 
									WHEN (
											(
												(T1."No_" LIKE 'W%')
												OR (T1."No_" LIKE '%I%')
												)
											)
										THEN ('Service')
									WHEN (
											((left(T1."No_", 2)) IN ('VG'))
											AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
											)
										THEN ('Teile')
									ELSE NULL
									END
								) = 'Teile'
							)
						THEN (
								(
									CASE 
										WHEN (
												(
													(
														CASE 
															WHEN (
																	(
																		(T1."No_" LIKE 'W%')
																		OR (T1."No_" LIKE '%I%')
																		)
																	)
																THEN ('Service')
															WHEN (
																	((left(T1."No_", 2)) IN ('VG'))
																	AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																	)
																THEN ('Teile')
															ELSE NULL
															END
														) = 'Teile'
													)
												AND (T2."Order No_" = '')
												)
											THEN ('Gutschrift ohne Auftrag')
										ELSE (T2."Order No_")
										END
									)
								)
					ELSE NULL
					END
				) AS "Service_Order_No_Teile_Order_No",
			CASE 
				WHEN (
						(
							(
								CASE 
									WHEN (
											(
												(T1."No_" LIKE 'W%')
												OR (T1."No_" LIKE '%I%')
												)
											)
										THEN ('Service')
									WHEN (
											((left(T1."No_", 2)) IN ('VG'))
											AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
											)
										THEN ('Teile')
									ELSE NULL
									END
								) = 'Teile'
							)
						AND (T2."Order No_" = '')
						)
					THEN ('Gutschrift ohne Auftrag')
				ELSE (T2."Order No_")
				END AS "Order No_",
			CASE 
				WHEN (T6."No_" IS NULL)
					THEN (T7."First Name" + ' ' + T7."Last Name")
				ELSE (T6."First Name" + ' ' + T6."Last Name")
				END AS "Serviceberater_Service",
			T8."Name" AS "Name_Salesperson",
			T8."Code" AS "Code_Salesperson",
			CASE 
				WHEN ((- 1 * datediff(day, (getdate()), T1."Posting Date")) <= 30)
					THEN (
							(
								CASE 
									WHEN (
											(
												CASE 
													WHEN (
															(
																CASE 
																	WHEN (
																			(
																				(T1."No_" LIKE 'W%')
																				OR (T1."No_" LIKE '%I%')
																				)
																			)
																		THEN ('Service')
																	WHEN (
																			((left(T1."No_", 2)) IN ('VG'))
																			AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																			)
																		THEN ('Teile')
																	ELSE NULL
																	END
																) = 'Service'
															)
														THEN (
																(
																	CASE 
																		WHEN (T2."Service Order No_" IS NULL)
																			THEN ('Gutschrift ohne Auftrag')
																		ELSE (T2."Service Order No_")
																		END
																	)
																)
													WHEN (
															(
																CASE 
																	WHEN (
																			(
																				(T1."No_" LIKE 'W%')
																				OR (T1."No_" LIKE '%I%')
																				)
																			)
																		THEN ('Service')
																	WHEN (
																			((left(T1."No_", 2)) IN ('VG'))
																			AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																			)
																		THEN ('Teile')
																	ELSE NULL
																	END
																) = 'Teile'
															)
														THEN (
																(
																	CASE 
																		WHEN (
																				(
																					(
																						CASE 
																							WHEN (
																									(
																										(T1."No_" LIKE 'W%')
																										OR (T1."No_" LIKE '%I%')
																										)
																									)
																								THEN ('Service')
																							WHEN (
																									((left(T1."No_", 2)) IN ('VG'))
																									AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																									)
																								THEN ('Teile')
																							ELSE NULL
																							END
																						) = 'Teile'
																					)
																				AND (T2."Order No_" = '')
																				)
																			THEN ('Gutschrift ohne Auftrag')
																		ELSE (T2."Order No_")
																		END
																	)
																)
													ELSE NULL
													END
												) = ' '
											)
										THEN ('Gutschrift ohne Auftrag')
									ELSE (
											(
												CASE 
													WHEN (
															(
																CASE 
																	WHEN (
																			(
																				(T1."No_" LIKE 'W%')
																				OR (T1."No_" LIKE '%I%')
																				)
																			)
																		THEN ('Service')
																	WHEN (
																			((left(T1."No_", 2)) IN ('VG'))
																			AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																			)
																		THEN ('Teile')
																	ELSE NULL
																	END
																) = 'Service'
															)
														THEN (
																(
																	CASE 
																		WHEN (T2."Service Order No_" IS NULL)
																			THEN ('Gutschrift ohne Auftrag')
																		ELSE (T2."Service Order No_")
																		END
																	)
																)
													WHEN (
															(
																CASE 
																	WHEN (
																			(
																				(T1."No_" LIKE 'W%')
																				OR (T1."No_" LIKE '%I%')
																				)
																			)
																		THEN ('Service')
																	WHEN (
																			((left(T1."No_", 2)) IN ('VG'))
																			AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																			)
																		THEN ('Teile')
																	ELSE NULL
																	END
																) = 'Teile'
															)
														THEN (
																(
																	CASE 
																		WHEN (
																				(
																					(
																						CASE 
																							WHEN (
																									(
																										(T1."No_" LIKE 'W%')
																										OR (T1."No_" LIKE '%I%')
																										)
																									)
																								THEN ('Service')
																							WHEN (
																									((left(T1."No_", 2)) IN ('VG'))
																									AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																									)
																								THEN ('Teile')
																							ELSE NULL
																							END
																						) = 'Teile'
																					)
																				AND (T2."Order No_" = '')
																				)
																			THEN ('Gutschrift ohne Auftrag')
																		ELSE (T2."Order No_")
																		END
																	)
																)
													ELSE NULL
													END
												)
											)
									END
								)
							)
				ELSE ('Auftr�ge �lter 30 Tage')
				END AS "Order_Desc_30",
			CASE 
				WHEN ((- 1 * datediff(day, (getdate()), T1."Posting Date")) <= 100)
					THEN (T1."No_" + ' - ' + T10."Name")
				ELSE ('Rechnungen �lter 100 Tage')
				END AS "Invoice_Desc_100",
			CASE 
				WHEN ((- 1 * datediff(day, (getdate()), T1."Posting Date")) <= 100)
					THEN (
							(
								CASE 
									WHEN (
											(
												CASE 
													WHEN (
															(
																CASE 
																	WHEN (
																			(
																				(T1."No_" LIKE 'W%')
																				OR (T1."No_" LIKE '%I%')
																				)
																			)
																		THEN ('Service')
																	WHEN (
																			((left(T1."No_", 2)) IN ('VG'))
																			AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																			)
																		THEN ('Teile')
																	ELSE NULL
																	END
																) = 'Service'
															)
														THEN (
																(
																	CASE 
																		WHEN (T2."Service Order No_" IS NULL)
																			THEN ('Gutschrift ohne Auftrag')
																		ELSE (T2."Service Order No_")
																		END
																	)
																)
													WHEN (
															(
																CASE 
																	WHEN (
																			(
																				(T1."No_" LIKE 'W%')
																				OR (T1."No_" LIKE '%I%')
																				)
																			)
																		THEN ('Service')
																	WHEN (
																			((left(T1."No_", 2)) IN ('VG'))
																			AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																			)
																		THEN ('Teile')
																	ELSE NULL
																	END
																) = 'Teile'
															)
														THEN (
																(
																	CASE 
																		WHEN (
																				(
																					(
																						CASE 
																							WHEN (
																									(
																										(T1."No_" LIKE 'W%')
																										OR (T1."No_" LIKE '%I%')
																										)
																									)
																								THEN ('Service')
																							WHEN (
																									((left(T1."No_", 2)) IN ('VG'))
																									AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																									)
																								THEN ('Teile')
																							ELSE NULL
																							END
																						) = 'Teile'
																					)
																				AND (T2."Order No_" = '')
																				)
																			THEN ('Gutschrift ohne Auftrag')
																		ELSE (T2."Order No_")
																		END
																	)
																)
													ELSE NULL
													END
												) = ' '
											)
										THEN ('Gutschrift ohne Auftrag')
									ELSE (
											(
												CASE 
													WHEN (
															(
																CASE 
																	WHEN (
																			(
																				(T1."No_" LIKE 'W%')
																				OR (T1."No_" LIKE '%I%')
																				)
																			)
																		THEN ('Service')
																	WHEN (
																			((left(T1."No_", 2)) IN ('VG'))
																			AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																			)
																		THEN ('Teile')
																	ELSE NULL
																	END
																) = 'Service'
															)
														THEN (
																(
																	CASE 
																		WHEN (T2."Service Order No_" IS NULL)
																			THEN ('Gutschrift ohne Auftrag')
																		ELSE (T2."Service Order No_")
																		END
																	)
																)
													WHEN (
															(
																CASE 
																	WHEN (
																			(
																				(T1."No_" LIKE 'W%')
																				OR (T1."No_" LIKE '%I%')
																				)
																			)
																		THEN ('Service')
																	WHEN (
																			((left(T1."No_", 2)) IN ('VG'))
																			AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																			)
																		THEN ('Teile')
																	ELSE NULL
																	END
																) = 'Teile'
															)
														THEN (
																(
																	CASE 
																		WHEN (
																				(
																					(
																						CASE 
																							WHEN (
																									(
																										(T1."No_" LIKE 'W%')
																										OR (T1."No_" LIKE '%I%')
																										)
																									)
																								THEN ('Service')
																							WHEN (
																									((left(T1."No_", 2)) IN ('VG'))
																									AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																									)
																								THEN ('Teile')
																							ELSE NULL
																							END
																						) = 'Teile'
																					)
																				AND (T2."Order No_" = '')
																				)
																			THEN ('Gutschrift ohne Auftrag')
																		ELSE (T2."Order No_")
																		END
																	)
																)
													ELSE NULL
													END
												)
											)
									END
								) + ' - ' + T10."Name"
							)
				ELSE ('Auftr�ge �lter 100 Tage')
				END AS "Order_Desc_100",
			T10."Post Code" AS "Post Code",
			(left(T10."Post Code", 4)) AS "PLZ_4_Stelle",
			(left(T10."Post Code", 3)) AS "PLZ_3_Stelle",
			(left(T10."Post Code", 2)) AS "PLZ_2_Stelle",
			(left(T10."Post Code", 1)) AS "PLZ_1_Stelle",
			CASE 
				WHEN (
						(
							CASE 
								WHEN (T2."Registration Date" <> convert(DATETIME, '1753-01-01 00:00:00.000'))
									THEN ((- 1 * datediff(day, T1."Posting Date", T2."Registration Date")))
								ELSE (0)
								END
							) / 365 BETWEEN 0.01 AND 0.99
						)
					THEN ('1')
				WHEN (
						(
							CASE 
								WHEN (T2."Registration Date" <> convert(DATETIME, '1753-01-01 00:00:00.000'))
									THEN ((- 1 * datediff(day, T1."Posting Date", T2."Registration Date")))
								ELSE (0)
								END
							) / 365 BETWEEN 1.00 AND 1.99
						)
					THEN ('2')
				WHEN (
						(
							CASE 
								WHEN (T2."Registration Date" <> convert(DATETIME, '1753-01-01 00:00:00.000'))
									THEN ((- 1 * datediff(day, T1."Posting Date", T2."Registration Date")))
								ELSE (0)
								END
							) / 365 BETWEEN 2.00 AND 2.99
						)
					THEN ('3')
				WHEN (
						(
							CASE 
								WHEN (T2."Registration Date" <> convert(DATETIME, '1753-01-01 00:00:00.000'))
									THEN ((- 1 * datediff(day, T1."Posting Date", T2."Registration Date")))
								ELSE (0)
								END
							) / 365 BETWEEN 3.00 AND 3.99
						)
					THEN ('4')
				WHEN (
						(
							CASE 
								WHEN (T2."Registration Date" <> convert(DATETIME, '1753-01-01 00:00:00.000'))
									THEN ((- 1 * datediff(day, T1."Posting Date", T2."Registration Date")))
								ELSE (0)
								END
							) / 365 BETWEEN 4.00 AND 4.99
						)
					THEN ('5')
				WHEN (
						(
							CASE 
								WHEN (T2."Registration Date" <> convert(DATETIME, '1753-01-01 00:00:00.000'))
									THEN ((- 1 * datediff(day, T1."Posting Date", T2."Registration Date")))
								ELSE (0)
								END
							) / 365 BETWEEN 5.00 AND 5.99
						)
					THEN ('6')
				WHEN (
						(
							CASE 
								WHEN (T2."Registration Date" <> convert(DATETIME, '1753-01-01 00:00:00.000'))
									THEN ((- 1 * datediff(day, T1."Posting Date", T2."Registration Date")))
								ELSE (0)
								END
							) / 365 BETWEEN 6.00 AND 6.99
						)
					THEN ('7')
				WHEN (
						(
							CASE 
								WHEN (T2."Registration Date" <> convert(DATETIME, '1753-01-01 00:00:00.000'))
									THEN ((- 1 * datediff(day, T1."Posting Date", T2."Registration Date")))
								ELSE (0)
								END
							) / 365 BETWEEN 7.00 AND 7.99
						)
					THEN ('8')
				WHEN (
						(
							CASE 
								WHEN (T2."Registration Date" <> convert(DATETIME, '1753-01-01 00:00:00.000'))
									THEN ((- 1 * datediff(day, T1."Posting Date", T2."Registration Date")))
								ELSE (0)
								END
							) / 365 BETWEEN 8.00 AND 8.99
						)
					THEN ('9')
				WHEN (
						(
							CASE 
								WHEN (T2."Registration Date" <> convert(DATETIME, '1753-01-01 00:00:00.000'))
									THEN ((- 1 * datediff(day, T1."Posting Date", T2."Registration Date")))
								ELSE (0)
								END
							) / 365 BETWEEN 9.00 AND 9.99
						)
					THEN ('10')
				WHEN (
						(
							CASE 
								WHEN (T2."Registration Date" <> convert(DATETIME, '1753-01-01 00:00:00.000'))
									THEN ((- 1 * datediff(day, T1."Posting Date", T2."Registration Date")))
								ELSE (0)
								END
							) / 365 > 9.99
						)
					THEN ('> 10')
				WHEN (
						(
							CASE 
								WHEN (T2."Registration Date" <> convert(DATETIME, '1753-01-01 00:00:00.000'))
									THEN ((- 1 * datediff(day, T1."Posting Date", T2."Registration Date")))
								ELSE (0)
								END
							) / 365 = 0
						)
					THEN ('keine Angabe')
				ELSE NULL
				END AS "FZG-Altersstaffel",
			(
				CASE 
					WHEN (T2."Registration Date" <> convert(DATETIME, '1753-01-01 00:00:00.000'))
						THEN ((- 1 * datediff(day, T1."Posting Date", T2."Registration Date")))
					ELSE (0)
					END
				) / 365 AS "Fahrzeugalter",
			T10."Name" AS "Cust_Name",
			T1."Gen_ Bus_ Posting Group" AS "Gen Bus Posting Group",
			CASE 
				WHEN (T2."Registration Date" <> convert(DATETIME, '1753-01-01 00:00:00.000'))
					THEN ((- 1 * datediff(day, T1."Posting Date", T2."Registration Date")))
				ELSE (0)
				END AS "Fahrzeugalter_Tage",
			T3."VIN" AS "Vin",
			T3."Model" AS "Model_ori",
			CASE 
				WHEN ((- 1 * datediff(day, (getdate()), T1."Posting Date")) <= 30)
					THEN (
							T1."No_" + ' - ' + (
								CASE 
									WHEN (
											(
												(
													CASE 
														WHEN (
																(
																	(T1."No_" LIKE 'W%')
																	OR (T1."No_" LIKE '%I%')
																	)
																)
															THEN ('Service')
														WHEN (
																((left(T1."No_", 2)) IN ('VG'))
																AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																)
															THEN ('Teile')
														ELSE NULL
														END
													) = 'Service'
												)
											AND (
												(
													CASE 
														WHEN (T6."No_" IS NULL)
															THEN (T7."First Name" + ' ' + T7."Last Name")
														ELSE (T6."First Name" + ' ' + T6."Last Name")
														END
													) <> ' '
												)
											)
										THEN (
												(
													CASE 
														WHEN (T6."No_" IS NULL)
															THEN (T7."First Name" + ' ' + T7."Last Name")
														ELSE (T6."First Name" + ' ' + T6."Last Name")
														END
													)
												)
									WHEN (
											(
												(
													CASE 
														WHEN (
																(
																	(T1."No_" LIKE 'W%')
																	OR (T1."No_" LIKE '%I%')
																	)
																)
															THEN ('Service')
														WHEN (
																((left(T1."No_", 2)) IN ('VG'))
																AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																)
															THEN ('Teile')
														ELSE NULL
														END
													) = 'Teile'
												)
											AND (T8."Name" IS NOT NULL)
											)
										THEN (T8."Name")
									ELSE ('n.N.')
									END
								) + ' - ' + T10."Name"
							)
				ELSE ('Rechnungen �lter 30 Tage')
				END AS "Invoice_Desc_30",
			CASE 
				WHEN (T2."Gen_ Prod_ Posting Group" LIKE '%ART%')
					THEN (((convert(FLOAT, T2."Amount"))) * - 1)
				ELSE (0)
				END AS "Umsatz Teile Service_ori",
			CASE 
				WHEN (T2."Gen_ Prod_ Posting Group" LIKE '%ART%')
					THEN (((convert(FLOAT, T2."Line Discount Amount"))) * - 1)
				ELSE (0)
				END AS "NL Teile_ori",
			CASE 
				WHEN (
						(
							(
								CASE 
									WHEN (T2."Gen_ Prod_ Posting Group" LIKE '%LOHN%')
										THEN (((convert(FLOAT, T2."Amount"))) * - 1)
									ELSE (0)
									END
								) + (
								CASE 
									WHEN (T2."Gen_ Prod_ Posting Group" LIKE '%LOHN%')
										THEN (((convert(FLOAT, T2."Line Discount Amount"))) * - 1)
									ELSE (0)
									END
								)
							) <> 0
						)
					THEN (
							(
								CASE 
									WHEN (T2."Gen_ Prod_ Posting Group" LIKE '%LOHN%')
										THEN (((convert(FLOAT, T2."Line Discount Amount"))) * - 1)
									ELSE (0)
									END
								) / (
								(
									CASE 
										WHEN (T2."Gen_ Prod_ Posting Group" LIKE '%LOHN%')
											THEN (((convert(FLOAT, T2."Amount"))) * - 1)
										ELSE (0)
										END
									) + (
									CASE 
										WHEN (T2."Gen_ Prod_ Posting Group" LIKE '%LOHN%')
											THEN (((convert(FLOAT, T2."Line Discount Amount"))) * - 1)
										ELSE (0)
										END
									)
								) * 100
							)
				ELSE (0)
				END AS "NL Lohn %",
			CASE 
				WHEN (T2."Gen_ Prod_ Posting Group" LIKE '%LOHN%')
					THEN (((convert(FLOAT, T2."Line Discount Amount"))) * - 1)
				ELSE (0)
				END AS "Rabatt Lohn",
			T1."Prices Including VAT" AS c186,
			(
				CASE 
					WHEN (T1."Location Code" IN ('01BSPKW'))
						THEN ('10')
					WHEN (T1."Location Code" IN ('02BSMOT'))
						THEN ('20')
					WHEN (T1."Location Code" IN ('03RHF'))
						THEN ('30')
					WHEN (T1."Location Code" IN ('04SFH'))
						THEN ('40')
					WHEN (T1."Location Code" IN ('05WT'))
						THEN ('50')
					WHEN (T1."Location Code" IN ('06BI'))
						THEN ('26')
					WHEN (T1."Location Code" IN ('07TR'))
						THEN ('70')
					ELSE NULL
					END
				) AS "Standort",
			((rtrim((((T2."Line No_"))))) + ' - ' + T1."No_" + ' - ' + T2."Description") AS "Auftragsposition",
			T11."No_" + ' - ' + T11."Name" AS "Kunde_Verkaufskunde",
			CASE 
				WHEN (T1."Sell-to Customer No_" LIKE 'INT%')
					THEN ('Intern')
				ELSE (T12."Description")
				END AS "Kundenart_Verkaufskunde",
			T12."Description" AS "Cust_Group_Description_Verkaufskunde",
			T11."Name" AS "Cust_Name_Verkaufskunde",
			T11."No_" AS "Cust_No_Verkaufskunde",
			CASE 
				WHEN ((- 1 * datediff(day, (getdate()), T1."Posting Date")) <= 4)
					THEN (
							(
								CASE 
									WHEN (T2."Service Order No_" IS NULL)
										THEN ('Gutschrift ohne Auftrag')
									ELSE (T2."Service Order No_")
									END
								)
							)
				ELSE NULL
				END AS "Order Number_Rg_Ausg_1",
			(
				substring(CASE 
						WHEN (
								((- 1 * datediff(day, (getdate()), T1."Posting Date")) <= 4)
								AND (
									(
										CASE 
											WHEN (
													(
														(
															CASE 
																WHEN (
																		(
																			(T1."No_" LIKE 'W%')
																			OR (T1."No_" LIKE '%I%')
																			)
																		)
																	THEN ('Service')
																WHEN (
																		((left(T1."No_", 2)) IN ('VG'))
																		AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																		)
																	THEN ('Teile')
																ELSE NULL
																END
															) = 'Service'
														)
													AND (
														(
															CASE 
																WHEN (T6."No_" IS NULL)
																	THEN (T7."First Name" + ' ' + T7."Last Name")
																ELSE (T6."First Name" + ' ' + T6."Last Name")
																END
															) <> ' '
														)
													)
												THEN (
														(
															CASE 
																WHEN (T6."No_" IS NULL)
																	THEN (T7."First Name" + ' ' + T7."Last Name")
																ELSE (T6."First Name" + ' ' + T6."Last Name")
																END
															)
														)
											WHEN (
													(
														(
															CASE 
																WHEN (
																		(
																			(T1."No_" LIKE 'W%')
																			OR (T1."No_" LIKE '%I%')
																			)
																		)
																	THEN ('Service')
																WHEN (
																		((left(T1."No_", 2)) IN ('VG'))
																		AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																		)
																	THEN ('Teile')
																ELSE NULL
																END
															) = 'Teile'
														)
													AND (T8."Name" IS NOT NULL)
													)
												THEN (T8."Name")
											ELSE ('n.N.')
											END
										) IS NOT NULL
									)
								)
							THEN (
									T1."No_" + ' - ' + (
										CASE 
											WHEN (
													(
														(
															CASE 
																WHEN (
																		(
																			(T1."No_" LIKE 'W%')
																			OR (T1."No_" LIKE '%I%')
																			)
																		)
																	THEN ('Service')
																WHEN (
																		((left(T1."No_", 2)) IN ('VG'))
																		AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																		)
																	THEN ('Teile')
																ELSE NULL
																END
															) = 'Service'
														)
													AND (
														(
															CASE 
																WHEN (T6."No_" IS NULL)
																	THEN (T7."First Name" + ' ' + T7."Last Name")
																ELSE (T6."First Name" + ' ' + T6."Last Name")
																END
															) <> ' '
														)
													)
												THEN (
														(
															CASE 
																WHEN (T6."No_" IS NULL)
																	THEN (T7."First Name" + ' ' + T7."Last Name")
																ELSE (T6."First Name" + ' ' + T6."Last Name")
																END
															)
														)
											WHEN (
													(
														(
															CASE 
																WHEN (
																		(
																			(T1."No_" LIKE 'W%')
																			OR (T1."No_" LIKE '%I%')
																			)
																		)
																	THEN ('Service')
																WHEN (
																		((left(T1."No_", 2)) IN ('VG'))
																		AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																		)
																	THEN ('Teile')
																ELSE NULL
																END
															) = 'Teile'
														)
													AND (T8."Name" IS NOT NULL)
													)
												THEN (T8."Name")
											ELSE ('n.N.')
											END
										) + ' - ' + T10."Name"
									)
						WHEN (
								((- 1 * datediff(day, (getdate()), T1."Posting Date")) <= 4)
								AND (
									(
										CASE 
											WHEN (
													(
														(
															CASE 
																WHEN (
																		(
																			(T1."No_" LIKE 'W%')
																			OR (T1."No_" LIKE '%I%')
																			)
																		)
																	THEN ('Service')
																WHEN (
																		((left(T1."No_", 2)) IN ('VG'))
																		AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																		)
																	THEN ('Teile')
																ELSE NULL
																END
															) = 'Service'
														)
													AND (
														(
															CASE 
																WHEN (T6."No_" IS NULL)
																	THEN (T7."First Name" + ' ' + T7."Last Name")
																ELSE (T6."First Name" + ' ' + T6."Last Name")
																END
															) <> ' '
														)
													)
												THEN (
														(
															CASE 
																WHEN (T6."No_" IS NULL)
																	THEN (T7."First Name" + ' ' + T7."Last Name")
																ELSE (T6."First Name" + ' ' + T6."Last Name")
																END
															)
														)
											WHEN (
													(
														(
															CASE 
																WHEN (
																		(
																			(T1."No_" LIKE 'W%')
																			OR (T1."No_" LIKE '%I%')
																			)
																		)
																	THEN ('Service')
																WHEN (
																		((left(T1."No_", 2)) IN ('VG'))
																		AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																		)
																	THEN ('Teile')
																ELSE NULL
																END
															) = 'Teile'
														)
													AND (T8."Name" IS NOT NULL)
													)
												THEN (T8."Name")
											ELSE ('n.N.')
											END
										) IS NULL
									)
								)
							THEN (T1."No_" + ' - ' + T10."Name")
						ELSE NULL
						END, 1, 100)
				) AS "Order Number_Rg_Ausg_2",
			(
				substring(CASE 
						WHEN (
								((- 1 * datediff(day, (getdate()), T1."Posting Date")) <= 30)
								AND (
									(
										CASE 
											WHEN (
													(
														(
															CASE 
																WHEN (
																		(
																			(T1."No_" LIKE 'W%')
																			OR (T1."No_" LIKE '%I%')
																			)
																		)
																	THEN ('Service')
																WHEN (
																		((left(T1."No_", 2)) IN ('VG'))
																		AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																		)
																	THEN ('Teile')
																ELSE NULL
																END
															) = 'Service'
														)
													AND (
														(
															CASE 
																WHEN (T6."No_" IS NULL)
																	THEN (T7."First Name" + ' ' + T7."Last Name")
																ELSE (T6."First Name" + ' ' + T6."Last Name")
																END
															) <> ' '
														)
													)
												THEN (
														(
															CASE 
																WHEN (T6."No_" IS NULL)
																	THEN (T7."First Name" + ' ' + T7."Last Name")
																ELSE (T6."First Name" + ' ' + T6."Last Name")
																END
															)
														)
											WHEN (
													(
														(
															CASE 
																WHEN (
																		(
																			(T1."No_" LIKE 'W%')
																			OR (T1."No_" LIKE '%I%')
																			)
																		)
																	THEN ('Service')
																WHEN (
																		((left(T1."No_", 2)) IN ('VG'))
																		AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																		)
																	THEN ('Teile')
																ELSE NULL
																END
															) = 'Teile'
														)
													AND (T8."Name" IS NOT NULL)
													)
												THEN (T8."Name")
											ELSE ('n.N.')
											END
										) IS NOT NULL
									)
								)
							THEN (
									T1."No_" + ' - ' + (
										CASE 
											WHEN (
													(
														(
															CASE 
																WHEN (
																		(
																			(T1."No_" LIKE 'W%')
																			OR (T1."No_" LIKE '%I%')
																			)
																		)
																	THEN ('Service')
																WHEN (
																		((left(T1."No_", 2)) IN ('VG'))
																		AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																		)
																	THEN ('Teile')
																ELSE NULL
																END
															) = 'Service'
														)
													AND (
														(
															CASE 
																WHEN (T6."No_" IS NULL)
																	THEN (T7."First Name" + ' ' + T7."Last Name")
																ELSE (T6."First Name" + ' ' + T6."Last Name")
																END
															) <> ' '
														)
													)
												THEN (
														(
															CASE 
																WHEN (T6."No_" IS NULL)
																	THEN (T7."First Name" + ' ' + T7."Last Name")
																ELSE (T6."First Name" + ' ' + T6."Last Name")
																END
															)
														)
											WHEN (
													(
														(
															CASE 
																WHEN (
																		(
																			(T1."No_" LIKE 'W%')
																			OR (T1."No_" LIKE '%I%')
																			)
																		)
																	THEN ('Service')
																WHEN (
																		((left(T1."No_", 2)) IN ('VG'))
																		AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																		)
																	THEN ('Teile')
																ELSE NULL
																END
															) = 'Teile'
														)
													AND (T8."Name" IS NOT NULL)
													)
												THEN (T8."Name")
											ELSE ('n.N.')
											END
										) + ' - ' + T10."Name" + ' - ' + (convert(VARCHAR(50), year(T1."Posting Date")) + '-' + convert(VARCHAR(50), month(T1."Posting Date")) + '-' + convert(VARCHAR(50), - 1 * datediff(day, T1."Posting Date")))
									)
						WHEN (
								((day((getdate()), T1."Posting Date")) <= 30)
								AND (
									(
										CASE 
											WHEN (
													(
														(
															CASE 
																WHEN (
																		(
																			(T1."No_" LIKE 'W%')
																			OR (T1."No_" LIKE '%I%')
																			)
																		)
																	THEN ('Service')
																WHEN (
																		((left(T1."No_", 2)) IN ('VG'))
																		AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																		)
																	THEN ('Teile')
																ELSE NULL
																END
															) = 'Service'
														)
													AND (
														(
															CASE 
																WHEN (T6."No_" IS NULL)
																	THEN (T7."First Name" + ' ' + T7."Last Name")
																ELSE (T6."First Name" + ' ' + T6."Last Name")
																END
															) <> ' '
														)
													)
												THEN (
														(
															CASE 
																WHEN (T6."No_" IS NULL)
																	THEN (T7."First Name" + ' ' + T7."Last Name")
																ELSE (T6."First Name" + ' ' + T6."Last Name")
																END
															)
														)
											WHEN (
													(
														(
															CASE 
																WHEN (
																		(
																			(T1."No_" LIKE 'W%')
																			OR (T1."No_" LIKE '%I%')
																			)
																		)
																	THEN ('Service')
																WHEN (
																		((left(T1."No_", 2)) IN ('VG'))
																		AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																		)
																	THEN ('Teile')
																ELSE NULL
																END
															) = 'Teile'
														)
													AND (T8."Name" IS NOT NULL)
													)
												THEN (T8."Name")
											ELSE ('n.N.')
											END
										) IS NULL
									)
								)
							THEN (T1."No_" + ' - ' + 'SB fehlt' + ' - ' + T10."Name" + ' - ' + (convert(VARCHAR(50), year(T1."Posting Date")) + '-' + convert(VARCHAR(50), month(T1."Posting Date")) + '-' + convert(VARCHAR(50), day(T1."Posting Date"))))
						ELSE ('Rechnungen �lter 30 Tage')
						END, 1, 100)
				) AS "Order Number_Rg_Ausg",
			CASE 
				WHEN ((- 1 * datediff(day, (getdate()), T1."Posting Date")) <= 180)
					THEN (
							T1."No_" + ' - ' + (
								CASE 
									WHEN (
											(
												CASE 
													WHEN (
															(
																CASE 
																	WHEN (
																			(
																				(T1."No_" LIKE 'W%')
																				OR (T1."No_" LIKE '%I%')
																				)
																			)
																		THEN ('Service')
																	WHEN (
																			((left(T1."No_", 2)) IN ('VG'))
																			AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																			)
																		THEN ('Teile')
																	ELSE NULL
																	END
																) = 'Service'
															)
														THEN (
																(
																	CASE 
																		WHEN (T2."Service Order No_" IS NULL)
																			THEN ('Gutschrift ohne Auftrag')
																		ELSE (T2."Service Order No_")
																		END
																	)
																)
													WHEN (
															(
																CASE 
																	WHEN (
																			(
																				(T1."No_" LIKE 'W%')
																				OR (T1."No_" LIKE '%I%')
																				)
																			)
																		THEN ('Service')
																	WHEN (
																			((left(T1."No_", 2)) IN ('VG'))
																			AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																			)
																		THEN ('Teile')
																	ELSE NULL
																	END
																) = 'Teile'
															)
														THEN (
																(
																	CASE 
																		WHEN (
																				(
																					(
																						CASE 
																							WHEN (
																									(
																										(T1."No_" LIKE 'W%')
																										OR (T1."No_" LIKE '%I%')
																										)
																									)
																								THEN ('Service')
																							WHEN (
																									((left(T1."No_", 2)) IN ('VG'))
																									AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																									)
																								THEN ('Teile')
																							ELSE NULL
																							END
																						) = 'Teile'
																					)
																				AND (T2."Order No_" = '')
																				)
																			THEN ('Gutschrift ohne Auftrag')
																		ELSE (T2."Order No_")
																		END
																	)
																)
													ELSE NULL
													END
												) = ' '
											)
										THEN ('Gutschrift ohne Auftrag')
									ELSE (
											(
												CASE 
													WHEN (
															(
																CASE 
																	WHEN (
																			(
																				(T1."No_" LIKE 'W%')
																				OR (T1."No_" LIKE '%I%')
																				)
																			)
																		THEN ('Service')
																	WHEN (
																			((left(T1."No_", 2)) IN ('VG'))
																			AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																			)
																		THEN ('Teile')
																	ELSE NULL
																	END
																) = 'Service'
															)
														THEN (
																(
																	CASE 
																		WHEN (T2."Service Order No_" IS NULL)
																			THEN ('Gutschrift ohne Auftrag')
																		ELSE (T2."Service Order No_")
																		END
																	)
																)
													WHEN (
															(
																CASE 
																	WHEN (
																			(
																				(T1."No_" LIKE 'W%')
																				OR (T1."No_" LIKE '%I%')
																				)
																			)
																		THEN ('Service')
																	WHEN (
																			((left(T1."No_", 2)) IN ('VG'))
																			AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																			)
																		THEN ('Teile')
																	ELSE NULL
																	END
																) = 'Teile'
															)
														THEN (
																(
																	CASE 
																		WHEN (
																				(
																					(
																						CASE 
																							WHEN (
																									(
																										(T1."No_" LIKE 'W%')
																										OR (T1."No_" LIKE '%I%')
																										)
																									)
																								THEN ('Service')
																							WHEN (
																									((left(T1."No_", 2)) IN ('VG'))
																									AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																									)
																								THEN ('Teile')
																							ELSE NULL
																							END
																						) = 'Teile'
																					)
																				AND (T2."Order No_" = '')
																				)
																			THEN ('Gutschrift ohne Auftrag')
																		ELSE (T2."Order No_")
																		END
																	)
																)
													ELSE NULL
													END
												)
											)
									END
								) + ' - ' + T10."Name"
							)
				ELSE ('Auftr�ge �lter 180 Tage')
				END AS "Order Number",
			T1."Posting Date" AS "Posting Date",
			CASE 
				WHEN (T2."Gen_ Prod_ Posting Group" LIKE '%LOHN%')
					THEN (((convert(FLOAT, T2."Quantity"))) * - 1)
				ELSE (0)
				END AS "verk Std",
			CASE 
				WHEN (T2."Gen_ Prod_ Posting Group" LIKE '%LOHN%')
					THEN (((convert(FLOAT, T2."Amount"))) * - 1)
				ELSE (0)
				END AS "Umsatz Lohn",
			T10."No_" + ' - ' + T10."Name" AS "Kunde",
			T10."No_" AS "Cust_No",
			CASE 
				WHEN (T1."Bill-to Customer No_" LIKE 'INT%')
					THEN ('Intern')
				ELSE (T9."Description")
				END AS "Kundenart",
			T9."Description" AS "Cust_Gr_Description",
			T9."Code" AS "Cust_Gr_Code",
			CASE 
				WHEN (
						(
							(T1."No_" LIKE 'W%')
							OR (T1."No_" LIKE '%I%')
							)
						)
					THEN ('Service')
				WHEN (
						((left(T1."No_", 2)) IN ('VG'))
						AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
						)
					THEN ('Teile')
				ELSE NULL
				END AS "Auftragsart",
			T5."Service Posting Group" AS "Service Posting Group",
			T4."Service Posting Group" AS "Service Posting Group_f�r_Archiv",
			CASE 
				WHEN (T1."Shortcut Dimension 2 Code" IN ('ALPINA', 'TRIUMPH', 'BMW-C1', 'BMW-ALPINA', 'BMWI', 'BMW', 'BMW-MINI', 'BMW-MOT'))
					THEN (T1."Shortcut Dimension 2 Code")
				ELSE ('Fremdfabrikat')
				END AS "Marke",
			T3."VIN" + ' - ' + T3."Model" AS "Fahrzeug",
			CASE 
				WHEN (T1."Shortcut Dimension 2 Code" IN ('BMW I', 'BMWI', 'BMW', 'BMW-MINI', 'BMW-C1', 'BMW-ALPINA', 'BMW-MOT', 'TRIUMPH'))
					THEN (T1."Shortcut Dimension 2 Code")
				WHEN (
						(
							CASE 
								WHEN (
										(
											CASE 
												WHEN (
														(
															CASE 
																WHEN (
																		(
																			(T1."No_" LIKE 'W%')
																			OR (T1."No_" LIKE '%I%')
																			)
																		)
																	THEN ('Service')
																WHEN (
																		((left(T1."No_", 2)) IN ('VG'))
																		AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																		)
																	THEN ('Teile')
																ELSE NULL
																END
															) = 'Service'
														)
													THEN (
															(
																CASE 
																	WHEN (T2."Service Order No_" IS NULL)
																		THEN ('Gutschrift ohne Auftrag')
																	ELSE (T2."Service Order No_")
																	END
																)
															)
												WHEN (
														(
															CASE 
																WHEN (
																		(
																			(T1."No_" LIKE 'W%')
																			OR (T1."No_" LIKE '%I%')
																			)
																		)
																	THEN ('Service')
																WHEN (
																		((left(T1."No_", 2)) IN ('VG'))
																		AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																		)
																	THEN ('Teile')
																ELSE NULL
																END
															) = 'Teile'
														)
													THEN (
															(
																CASE 
																	WHEN (
																			(
																				(
																					CASE 
																						WHEN (
																								(
																									(T1."No_" LIKE 'W%')
																									OR (T1."No_" LIKE '%I%')
																									)
																								)
																							THEN ('Service')
																						WHEN (
																								((left(T1."No_", 2)) IN ('VG'))
																								AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																								)
																							THEN ('Teile')
																						ELSE NULL
																						END
																					) = 'Teile'
																				)
																			AND (T2."Order No_" = '')
																			)
																		THEN ('Gutschrift ohne Auftrag')
																	ELSE (T2."Order No_")
																	END
																)
															)
												ELSE NULL
												END
											) = ' '
										)
									THEN ('Gutschrift ohne Auftrag')
								ELSE (
										(
											CASE 
												WHEN (
														(
															CASE 
																WHEN (
																		(
																			(T1."No_" LIKE 'W%')
																			OR (T1."No_" LIKE '%I%')
																			)
																		)
																	THEN ('Service')
																WHEN (
																		((left(T1."No_", 2)) IN ('VG'))
																		AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																		)
																	THEN ('Teile')
																ELSE NULL
																END
															) = 'Service'
														)
													THEN (
															(
																CASE 
																	WHEN (T2."Service Order No_" IS NULL)
																		THEN ('Gutschrift ohne Auftrag')
																	ELSE (T2."Service Order No_")
																	END
																)
															)
												WHEN (
														(
															CASE 
																WHEN (
																		(
																			(T1."No_" LIKE 'W%')
																			OR (T1."No_" LIKE '%I%')
																			)
																		)
																	THEN ('Service')
																WHEN (
																		((left(T1."No_", 2)) IN ('VG'))
																		AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																		)
																	THEN ('Teile')
																ELSE NULL
																END
															) = 'Teile'
														)
													THEN (
															(
																CASE 
																	WHEN (
																			(
																				(
																					CASE 
																						WHEN (
																								(
																									(T1."No_" LIKE 'W%')
																									OR (T1."No_" LIKE '%I%')
																									)
																								)
																							THEN ('Service')
																						WHEN (
																								((left(T1."No_", 2)) IN ('VG'))
																								AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																								)
																							THEN ('Teile')
																						ELSE NULL
																						END
																					) = 'Teile'
																				)
																			AND (T2."Order No_" = '')
																			)
																		THEN ('Gutschrift ohne Auftrag')
																	ELSE (T2."Order No_")
																	END
																)
															)
												ELSE NULL
												END
											)
										)
								END
							) = 'Gutschrift ohne Auftrag'
						)
					THEN ('GS ohne Auftrag')
				ELSE ('Fremdfabrikat')
				END AS "Fabrikat",
			CASE 
				WHEN (T1."Customer Posting Group" IN ('PKW_GWL'))
					THEN ('GWL')
				WHEN (T1."No_ Series" LIKE 'I%')
					THEN ('Intern')
				ELSE ('Extern')
				END AS "Umsatzart",
			CASE 
				WHEN (
						(
							(
								CASE 
									WHEN (
											(
												(T1."No_" LIKE 'W%')
												OR (T1."No_" LIKE '%I%')
												)
											)
										THEN ('Service')
									WHEN (
											((left(T1."No_", 2)) IN ('VG'))
											AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
											)
										THEN ('Teile')
									ELSE NULL
									END
								) = 'Service'
							)
						AND (
							(
								CASE 
									WHEN (T6."No_" IS NULL)
										THEN (T7."First Name" + ' ' + T7."Last Name")
									ELSE (T6."First Name" + ' ' + T6."Last Name")
									END
								) <> ' '
							)
						)
					THEN (
							(
								CASE 
									WHEN (T6."No_" IS NULL)
										THEN (T7."First Name" + ' ' + T7."Last Name")
									ELSE (T6."First Name" + ' ' + T6."Last Name")
									END
								)
							)
				WHEN (
						(
							(
								CASE 
									WHEN (
											(
												(T1."No_" LIKE 'W%')
												OR (T1."No_" LIKE '%I%')
												)
											)
										THEN ('Service')
									WHEN (
											((left(T1."No_", 2)) IN ('VG'))
											AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
											)
										THEN ('Teile')
									ELSE NULL
									END
								) = 'Teile'
							)
						AND (T8."Name" IS NOT NULL)
						)
					THEN (T8."Name")
				ELSE ('n.N.')
				END AS "Serviceberater",
			T7."Last Name" AS "Last Name",
			T7."First Name" AS "First Name",
			T7."No_" AS "No_SB",
			T6."Last Name" AS "Last Name_f�r_Archiv",
			T6."First Name" AS "First Name_f�r_Archiv",
			T6."No_" AS "No_f�r_Archiv",
			T5."Service Advisor No_" AS "Service Advisor No_oA",
			T4."Service Advisor No_" AS "Service Advisor No_Archiv",
			T2."Item Group Code" AS "Item Group Code",
			T2."Customer Group Code" AS "Customer Group Code",
			T2."Labor No_" AS "Labor No",
			T2."Service Order Line No_" AS "Service Order Line No",
			CASE 
				WHEN (T2."Service Order No_" IS NULL)
					THEN ('Gutschrift ohne Auftrag')
				ELSE (T2."Service Order No_")
				END AS "Service Order No_",
			T2."Mileage" AS "Mileage",
			T2."Registration Date" AS "Registration Date",
			T2."Vehicle Status" AS "Vehicle Status",
			T2."Item Type" AS "Item Type",
			T2."Order Type" AS "Order Type",
			T2."Order Line No_" AS "Order Line No",
			T2."Order No_" AS "Order No",
			T2."Unit Cost" AS "Unit Cost",
			(convert(FLOAT, T2."Amount")) AS "Amount",
			(convert(FLOAT, T2."Line Discount Amount")) AS "Line Discount Amount",
			T2."Unit Cost (LCY)" AS "Unit Cost (lcy)",
			T2."Unit Price" AS "Unit Price",
			(convert(FLOAT, T2."Quantity")) AS "Quantity",
			T2."Description" AS "Description",
			T2."No_" AS "No_Pos.",
			T2."Type" AS "Type",
			T2."Line No_" AS "Line No",
			T2."Document No_" AS "Document No",
			T1."Branch Code" AS "Branch Code",
			CASE 
				WHEN (
						(
							CASE 
								WHEN (
										(
											CASE 
												WHEN (
														(
															(T1."No_" LIKE 'W%')
															OR (T1."No_" LIKE '%I%')
															)
														)
													THEN ('Service')
												WHEN (
														((left(T1."No_", 2)) IN ('VG'))
														AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
														)
													THEN ('Teile')
												ELSE NULL
												END
											) = 'Service'
										)
									THEN (
											(
												CASE 
													WHEN (T2."Service Order No_" IS NULL)
														THEN ('Gutschrift ohne Auftrag')
													ELSE (T2."Service Order No_")
													END
												)
											)
								WHEN (
										(
											CASE 
												WHEN (
														(
															(T1."No_" LIKE 'W%')
															OR (T1."No_" LIKE '%I%')
															)
														)
													THEN ('Service')
												WHEN (
														((left(T1."No_", 2)) IN ('VG'))
														AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
														)
													THEN ('Teile')
												ELSE NULL
												END
											) = 'Teile'
										)
									THEN (
											(
												CASE 
													WHEN (
															(
																(
																	CASE 
																		WHEN (
																				(
																					(T1."No_" LIKE 'W%')
																					OR (T1."No_" LIKE '%I%')
																					)
																				)
																			THEN ('Service')
																		WHEN (
																				((left(T1."No_", 2)) IN ('VG'))
																				AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																				)
																			THEN ('Teile')
																		ELSE NULL
																		END
																	) = 'Teile'
																)
															AND (T2."Order No_" = '')
															)
														THEN ('Gutschrift ohne Auftrag')
													ELSE (T2."Order No_")
													END
												)
											)
								ELSE NULL
								END
							) = ' '
						)
					THEN ('Gutschrift ohne Auftrag')
				ELSE (
						(
							CASE 
								WHEN (
										(
											CASE 
												WHEN (
														(
															(T1."No_" LIKE 'W%')
															OR (T1."No_" LIKE '%I%')
															)
														)
													THEN ('Service')
												WHEN (
														((left(T1."No_", 2)) IN ('VG'))
														AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
														)
													THEN ('Teile')
												ELSE NULL
												END
											) = 'Service'
										)
									THEN (
											(
												CASE 
													WHEN (T2."Service Order No_" IS NULL)
														THEN ('Gutschrift ohne Auftrag')
													ELSE (T2."Service Order No_")
													END
												)
											)
								WHEN (
										(
											CASE 
												WHEN (
														(
															(T1."No_" LIKE 'W%')
															OR (T1."No_" LIKE '%I%')
															)
														)
													THEN ('Service')
												WHEN (
														((left(T1."No_", 2)) IN ('VG'))
														AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
														)
													THEN ('Teile')
												ELSE NULL
												END
											) = 'Teile'
										)
									THEN (
											(
												CASE 
													WHEN (
															(
																(
																	CASE 
																		WHEN (
																				(
																					(T1."No_" LIKE 'W%')
																					OR (T1."No_" LIKE '%I%')
																					)
																				)
																			THEN ('Service')
																		WHEN (
																				((left(T1."No_", 2)) IN ('VG'))
																				AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
																				)
																			THEN ('Teile')
																		ELSE NULL
																		END
																	) = 'Teile'
																)
															AND (T2."Order No_" = '')
															)
														THEN ('Gutschrift ohne Auftrag')
													ELSE (T2."Order No_")
													END
												)
											)
								ELSE NULL
								END
							)
						)
				END AS "Service Order No_ohne_Einschr�nkung",
			T1."User ID" AS "User Id",
			T1."Document Date" AS "Document Date",
			T1."Sell-to City" AS "Sell-to City",
			T1."Sell-to Customer Name" AS "Sell-to Customer Name",
			T1."Salesperson Code" AS "Salesperson Code",
			T1."Shortcut Dimension 2 Code" AS "Make Code",
			T1."Shortcut Dimension 1 Code" AS "Department Code",
			T1."Location Code" AS "Location Code",
			T1."Bill-to City" AS "Bill-to City",
			T1."Bill-to Name" AS "Bill-to Name",
			T1."Bill-to Customer No_" AS "Bill-to Customer No",
			T1."Sell-to Customer No_" AS "Sell-to Customer No"
		FROM (
			(
				(
					(
						(
							(
								"Gottstein7x"."dbo"."AH Gottstein$Sales Credit Memo Header" T1 LEFT JOIN "Gottstein7x"."dbo"."AH Gottstein$Vehicle" T3 ON T1."Supply VIN" = T3."VIN"
								) LEFT JOIN "Gottstein7x"."dbo"."AH Gottstein$Salesperson_Purchaser" T8 ON T8."Code" = T1."Salesperson Code"
							) LEFT JOIN "Gottstein7x"."dbo"."AH Gottstein$Customer" T10 ON T1."Bill-to Customer No_" = T10."No_"
						) LEFT JOIN "Gottstein7x"."dbo"."AH Gottstein$Customer Group" T9 ON T10."Customer Group Code" = T9."Code"
					) LEFT JOIN "Gottstein7x"."dbo"."AH Gottstein$Customer" T11 ON T11."No_" = T1."Sell-to Customer No_"
				) LEFT JOIN "Gottstein7x"."dbo"."AH Gottstein$Customer Group" T12 ON T11."Customer Group Code" = T12."Code"
			),
			(
				(
					(
						(
							"Gottstein7x"."dbo"."AH Gottstein$Sales Credit Memo Line" T2 LEFT JOIN "Gottstein7x"."dbo"."AH Gottstein$Archived Service Header" T4 ON T4."No_" = T2."Service Order No_"
							) LEFT JOIN "Gottstein7x"."dbo"."AH Gottstein$Service Header" T5 ON T5."No_" = T2."Service Order No_"
						) LEFT JOIN "Gottstein7x"."dbo"."AH Gottstein$Employee" T6 ON T4."Service Advisor No_" = T6."No_"
					) LEFT JOIN "Gottstein7x"."dbo"."AH Gottstein$Employee" T7 ON T5."Service Advisor No_" = T7."No_"
				)
		WHERE (T1."No_" = T2."Document No_")
			AND (
				(
					(
						(
							(T1."No_" LIKE 'W%')
							OR (T1."No_" LIKE '%I%')
							)
						OR (
							((left(T1."No_", 2)) IN ('VG'))
							AND (NOT (left(T1."No_", 4)) IN ('VGGF'))
							)
						)
					AND (NOT T2."Type" IN (0, 11, 12))
					)
				AND (T1."Posting Date" >= convert(DATETIME, '2022-01-01 00:00:00.000'))
				)
		) D1
	) D4
	-- order by "No" asc
