My ERP uses parameters within a square bracket but in some cases I'll need to enter more than one and not to have multiple versions help.
--Change the years to match the year
--Will need excel formulas for blank columns see code for details
SELECT T0.SuppCatNum AS 'Part Number',
T0.[ItemCode], -- inverted the order of the first 2 columns to get the correct vlookup
T0.[ItemName], T0.[OnHand],
T0.[NumInBuy] AS 'Items per Purchasing Unit',
T0.[LastPurPrc] AS 'Purchase Price 2021',
'=IFNA(VLOOKUP(A2,"2022 Price List"!A:P,16,FALSE),"")' AS 'New Buying Price 2022', -- =IFNA(VLOOKUP(A2,'2022 Price List'!A:P,16,FALSE),"") second parameter in Vlookup should be name of price sheet with the column of the price
T2.[Price] AS '01 Liste de Prix 2021',
'=IFERROR(ROUND(G2/E2,2),"")' AS 'New cost per UoM 2022', -- =IFERROR(ROUND(G2/E2,2),"") is New Buying Price 2022 / Items per Purchasing Unit
'=IFERROR(I2-F2,"")' AS 'Difference per unit', -- =IFERROR(I2-F2,"") for first row to calculate difference
'=IF(ISERROR(VLOOKUP(A2,"2022 Price List"!A:A,1,FALSE)),"Not on price list","")' AS 'If item is on price list' -- =IF(ISERROR(VLOOKUP(A2,'2022 Price List'!A:A,1,FALSE)),"Not on price list","") second parameter in Vlookup should be name of price sheet
FROM OITM T0 INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode
INNER JOIN ITM1 T2 ON T0.ItemCode = T2.ItemCode
WHERE T2.[PriceList] ='1'
and t0.cardcode ='[%0]'
and t0.ValidFor='Y'