I have a MS Query
connection from Excel 2016
sheet to IBM DB2
database. I use parameterized query and link parameter values to Excel cell. While "singular value" clauses such as = < > like
work, I can't get IN
clause to work with multiple values but otherwise super simple query.
Here's a simple demo dataset how I produce the parameter values:
Column D formula is =IF(C2>5,A2&",","")
which checks column C value for higher than 5 and populates ID
in column D if TRUE
. I'm expecting to use a helper cell to merge/concat all values in column D which I want to use for IN
clause as value (yet to be completed).
How can I use "value1, value2, value3, ..."
in a cell to run an IN
clause query? Is it possible at all? IN
clause works fine when the linked cell holds value 1
however 1, 3
produces error message:
"Bad parameter type. Microsoft Excel is expecting a different kind of value than what was provided"
.
Using a separate parameter and OR
clause for each cell technically looks to work, however in practice the dataset can easily reach 50-100 values which means crazy amount of parameter setup.
Query itself is something as simple as:
select * from PRODUCTS a
where a.prod_ID in (1,3)
or as Excel MS Query alternative:
select * from PRODUCTS a
where a.prod_ID in ?