use AlplaPROD_test1

SELECT plant=(SELECT Wert FROM dbo.T_SystemParameter (nolock) WHERE (Bezeichnung = 'Werkskuerzel')),
plantName=(SELECT Wert FROM dbo.T_SystemParameter AS T_SystemParameter (nolock) WHERE (Bezeichnung = 'Mandant-intern')),*
    from 
    (Select IdBestellung as 'Purchase order number', 
	IdArtikelVarianten AS AV, 
	BestellMenge, 
	BestellMengeVPK,
	PreisProEinheit, 
	convert(varchar,Lieferdatum,23) as deliveryDate, 
	ROW_NUMBER() over(partition by IdArtikelVarianten order by Lieferdatum desc) rn 
from dbo.V_Bestellpositionen_PURCHASE (nolock)
    where PositionsStatus = '7' or PositionsStatus = '6' or PositionsStatus = '5' and convert(varchar,Lieferdatum,23) > DATEADD(year, -5, GetDate()) )a
     where rn = 1