Um eine Union Select auszuführen, musst du den Code für jeden Wert von "XXX" einzeln ausführen. Hier ist der Code mit den ersten beiden Werten 460 und 270:
Select
'460' as BCN,
inv100.tcprjasProjekt,inv100.titem as Artikelnr,
itm001.dsca as Artikelbez,
inv100.tcwarasLager,inv100.tidat as Erfassungsdatum,
inv100.ttrdtasA¨nderungsdatum,(Caseinv100.tkowt
when 1 then 'Bestellung'
when 2 then 'VK-Auftrag'
when 3 then 'Produktionsentnahme'
when 4 then 'Produktionseingang'
when 5 then 'Vorratskorrektur'
when 6 then 'Vorratsumbuchung'
End) as Änderungsart,
inv100.tcompasFirmaFibu,inv100.tpqan as Geplante_Menge,
inv100.tdqanasGelieferteMenge,inv100.tlogn as Login_Code,
inv100.twrhoasLagerauftragsnr,inv700.tquan as Lagerbestand_nach_Änderung,
inv100.t$recd as Grund
from ( Select * from baan.ttdinv100460@baan where trim(trecd)isnullandtkowt = 5 and titem) = itm001.item and itm001.bcn = 460
left join (Select * from ( Select RANK() OVER (PARTITION BY tcwar ORDER BY ttrtm DESC) AS DateTimestampRank,
tcwar, tkost, ttrdt > to_date('01.01.2022', 'dd.mm.yyyy') and titem = inv700.tcwar = inv700.ttrdt = inv700.t$trdt
where trim(inv100.trecd)isnullandinv100.tkowt = 5
and inv100.t$trdt > to_date('01.01.2022', 'dd.mm.yyyy')
UNION
Select
'270' as BCN,
inv100.tcprjasProjekt,inv100.titem as Artikelnr,
itm001.dsca as Artikelbez,
inv100.tcwarasLidat as Erfassungsdatum,
inv100.tkowt
when 1 then 'Bestellung'
when 2 then 'VK-Auftrag'
when 3 then 'Produktionsentnahme'
when 4 then 'Produktionseingang'
when 5 then 'Vorratskorrektur'
when 6 then 'Vorratsumbuchung'
End) as Änderungsart,
inv100.tpqan as Geplante_Menge,
inv100.tlogn as Login_Code,
inv100.tquan as Lagerbestand_nach_Änderung,
inv100.t$recd as Grund
from ( Select * from baan.ttdinv100270@baan where trim(trecd)isnullandtkowt = 5 and titem) = itm001.item and itm001.bcn = 270
left join (Select * from ( Select RANK() OVER (PARTITION BY tcwar ORDER BY ttrtm DESC) AS DateTimestampRank,
tcwar, tkost, ttrdt > to_date('01.01.2022', 'dd.mm.yyyy') and titem = inv700.tcwar = inv700.ttrdt = inv700.t$trdt
where trim(inv100.trecd)isnullandinv100.tkowt = 5
and inv100.t$trdt > to_date('01.01.2022', 'dd.mm.yyyy')