SELECT
	CAST(pdb_el.auftraege.produktionsauftrag AS INT) AS production_order
	,pdb_el.auftraege.artikelcode AS article_code
	,(CASE WHEN ISNULL(pdb_el.anonyme_cg_geraete.C_Nummer) THEN FALSE ELSE TRUE END) AS is_anonymous
	,(CASE WHEN ISNULL(pdb_el.anonyme_cg_geraete.Artikelcode) THEN (CASE WHEN pdb_el.auftraege.C_Nummer = "" THEN NULL ELSE pdb_el.auftraege.C_Nummer END) ELSE pdb_el.anonyme_cg_geraete.C_Nummer END) AS cg_number
	,pdb_el.auftraege.stueckzahl AS number_of_pieces
	,pdb_el.auftraege.IX AS bom_index
	,pdb_el.auftraege.referenz_dokument AS reference_document
FROM pdb_el.auftraege
LEFT JOIN pdb_el.anonyme_cg_geraete ON pdb_el.auftraege.artikelcode = pdb_el.anonyme_cg_geraete.Artikelcode
WHERE pdb_el.auftraege.produktionsauftrag = 14114074
