Array in a query

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
rvzip64
Posts: 17
Joined: Wed 19 Sep 2007 08:51

Array in a query

Post by rvzip64 » Thu 17 Dec 2009 10:59

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

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Thu 17 Dec 2009 13:51

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(')');

Post Reply