Subject | Re: [IBO] list of values in a parameter |
---|---|
Author | Ben Malings |
Post date | 2013-03-19T16:05:46Z |
> I've found it works to build the SQL in the Delphi code, somewhatlike this:
>That's OK for integers but it doesn't use parameters, so I wouldn't use
> with theQuery do
> begin
> Close;
> SQL.Clear;
> SQL.Add('select * from the_table where thetable_key in (' +
> my_StringList.CommaText + ') ' );
> Open;
> ...
> end;
it for string fields.
For a stringlist of arbitrary length, something like this should work
(not tested so excuse any bugs):
qry.SQL.Add('where the_table_key in (:p0');
qry.Params[0].AsString := my_StringList[0];
for i := 1 to my_StringList.Count - 1 do begin
qry.SQL.Add(Format(',:p%d',[i]));
qry.Params[i].AsString := my_StringList[i];
end;
qry.SQL.Add(')');