SELECT DISTINCT T1."Service Order No_" AS "Service Order No",
	CASE 
		WHEN (T2."Gen_ Prod_ Posting Group" IN ('821_SONST', '823_SONST', '828_SONST', '822_SONST', '824_SONST', '825_SONST', '826_SONST', '827_SONST', '829_SONST'))
			THEN ('mit Fremdl.')
		ELSE ('ohne Fremdl.')
		END AS "Fremdl_ja_nein"
FROM "Gottstein7x"."dbo"."AH Gottstein$Sales Invoice Header" T1,
	"Gottstein7x"."dbo"."AH Gottstein$Sales Invoice Line" T2
WHERE (T1."No_" = T2."Document No_")
	AND (
		(
			(T1."Service Order No_" <> '')
			AND (T1."Service Order No_" LIKE 'WAU%')
			)
		AND (
			(
				CASE 
					WHEN (T2."Gen_ Prod_ Posting Group" IN ('821_SONST', '823_SONST', '828_SONST', '822_SONST', '824_SONST', '825_SONST', '826_SONST', '827_SONST', '829_SONST'))
						THEN ('mit Fremdl.')
					ELSE ('ohne Fremdl.')
					END
				) = 'mit Fremdl.'
			)
		)
	-- order by "Service Order No" asc
