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

4

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

SQL command used in the parameterized component:

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

SQL command without 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 :bloqueado parameter as shown below?

Query.PramByName(bloqueado).AsString:= '1,2'
    
asked by anonymous 11.06.2014 / 14:17

3 answers

2

As you are interested in an outline, it follows:

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, within the square brackets you will define your integer parameter.

    
11.06.2014 / 20:27
2

There is no way to do what you want by using parameters. Parameters do not work like that . You can try some alternatives , such as:

  • Change SQL "on hand" as answered by Filipe Fonseca
  • Use temporary tables and make a join
  • Use a procedure that turns the parameter into a list
  • other more obscure ways:)
20.06.2014 / 21:42
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;
    
01.09.2017 / 16:37