Page 1 of 1

Array in a query

Posted: Thu 17 Dec 2009 10:59
by rvzip64
Hi,

I would like to create a query like this

Code: Select all

Select * from table where (id=1 or id=2 or id=3)
My Id is store in an array of string.

It is possible to do that in automatic ?


Thank's

Posted: Thu 17 Dec 2009 13:51
by Dimon
You can use the following code:

Code: Select all

MyQuery.SQL.Clear;
MyQuery.SQL.Add('select * from table');
MyQuery.SQL.Add('where id IN (');
for i := 0 to Length(arr) - 1 do
  MyQuery.SQL.Add(arr[i] + ',');
MyQuery.SQL.Add(')');