Hello,
I want to create a statement like 'SELECT * FROM table WHERE parameter IN (valuelist);'
I know how to use parameters in general, e.g.
q.SQL.Text := 'SELECT * FROM table WHERE id=:ID;'
q.ParamByName('id').AsInteger := 42;
But for the IN-statement, I have to pass an array and do not know how to do it. There is no ParamByName().AsArray property.
Howto use parameters in SELECT WHERE ... IN ... query
Re: Howto use parameters in SELECT WHERE ... IN ... query
Please specify the database you are working with. Usage of the AsArray property requires support at the DBMS side. In case of a fixed number of elements of the parameter list, you can describe each of them in a query:
In case of varying number of elements, you can use a macro:
In this case, list values can be filled in as follows:
Code: Select all
'SELECT * FROM table WHERE parameter IN (:value1, :value2, :value3, :value4)' Code: Select all
'SELECT * FROM table WHERE parameter IN (&valuelist)' Code: Select all
q.MacroByName('valuelist').Value := '7521, 7788, 7900';