Subject | Re: [IBO] Passing a list of parameters to a query |
---|---|
Author | Geoff Worboys |
Post date | 2015-12-29T14:22:47Z |
Short answer: No.
Longer answer:
A single parameter is a single value as far as the server is concerned.
When you type:
Select ID, Value from Table where ID in (:List)
What IBO actually sends to the server during prepare is:
Select ID, Value from Table where ID in ( ? )
And when the server returns from the prepare it tells IBO what type of data is acceptable for that unnamed parameter - which IBO conveniently makes available for you under the name: List.
This should work I imagine (have never tried it), if you always want exactly three items in your list:
Select ID, Value from Table where ID in (:ID1, :ID2, :ID3)
With enough thought there is might be a way to build a select statement that would extract out your integers from your string ('1,2,3') and place them in the IN clause. eg:
Select ID, Value from Table
where ID in ( SELECT i FROM MyProc( :List ) )
Where MyProc is a selectable procedure that pulls apart your string. (FB v2.5 required.)
But I'm guessing your easiest solution is to replace the WHERE clause as needed.
--
Geoff Worboys
Telesis Computing Pty Ltd
FHector@... [IBObjects] wrote:
Hi, when I define a query as such: Select ID, Value from Table where ID in (1,2,3) this works w/o a problem. Yet, when I define the query as Select ID, Value from Table where ID in (:List) and try to pass the list with ...ParamByName('List').AsString := '1,2,3', I get an error message saying that '1,2,3' is not a valid integer value. Is it possible to pass such a list to a query? Florian |