Use of parameters in the "in" clause in a Tibquery

Asked

Viewed 1,370 times

4

I have the following SQL command in the SQL property of a Tibquery component in Delphi.

SQL command used in the component with parameters:

select pro_codigo, pro_nome 
  from produtos 
 where pro_fis_codigo = :fis_codigo 
   and pro_bloqueado in (:bloqueado)

SQL command without the parameters:

select pro_codigo, pro_nome 
  from produtos 
 where pro_fis_codigo = 1 
   and pro_bloqueado in (1,2)

Is there any way to use the parameter :bloqueado as an example below?

Query.PramByName(bloqueado).AsString:= '1,2'

3 answers

2

2

Since you’re interested in an outline, follow:

Instead of passing a parameter only with everything you want to put, try the following.

IBQuery1.SQL.Clear;
IBQuery1.SQL.Text := Format('Select pro_codigo, pro_nome from produtos where pro_fis_codigo = :fis_codigo and pro_bloqueado in (%s)',[QuotedStr('ParametroVarChar') + ',' + 'Parametro Numero']);

So, inside the brackets you will set your integer parameter.

0

query := '(1,28,32,88,91,9355)';

IBQProduto.Close;
IBQProduto.SQL.Clear;
IBQProduto.SQL.Add('select * from produto pro');
IBQProduto.SQL.Add('where pro.item in ' + query);
IBQProduto.SQL.Add('order by pro.item asc');
IBQProduto.Open;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.