Rewrite ERP paramater to accept one or more values.

Jonathan Brotto 1,076 Reputation points
2022-03-30T18:55:46.06+00:00

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'
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,642 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,547 questions
{count} votes

Accepted answer
  1. Olaf Helper 40,656 Reputation points
    2022-03-31T13:25:52.18+00:00

    to run a report for 2 or more companies

    For this you can use the IN operator, like

     WHERE T2.[PriceList] ='1'  
         and t0.cardcode ('[%0]', '[%1]', '[%2]')  
    

    See https://learn.microsoft.com/en-us/sql/t-sql/language-elements/in-transact-sql?view=sql-server-ver15


0 additional answers

Sort by: Most helpful