DELPHI 7 - Query

danz67
danz67 used Ask the Experts™
on
I get the records that contain different parameters, the problem is parameter: STATO I need to search for all records containing the parameter: STATO with value 'RIENTRATO and RIPARATO, I tried with this code, but I get no records displayed
with DataModule2.QAssistenze do
  begin
  SQL.Text :=
    'select * from riparazioni where cliente = :cliente  '+
       'and StatoAssistenza like :stato '+
       'and accettazioneanno = :anno';
     Params.ParamByName('CLIENTE').AsString := combocliente.EditingText;
     Params.ParamByName('STATO').AsString := '%' + 'RIENTRATO RIPARATO' + '%';
     Params.ParamByName('ANNO').AsString := comboanno.Text;
     open;
  end;

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Hi, try it like this

with DataModule2.QAssistenze do
  begin
  SQL.Text :=
    'select * from riparazioni where cliente = :cliente  '+
       'and StatoAssistenza like :stato '+
       'and accettazioneanno = :anno';
     Params.ParamByName('CLIENTE').AsString := QuotedStr(combocliente.EditingText);
     Params.ParamByName('STATO').AsString := QuotedStr('%' + 'RIENTRATO RIPARATO' + '%');
     Params.ParamByName('ANNO').AsString := QuotedStr(comboanno.Text);
     open;
  end;
Freelance Project Manager
Top Expert 2010
Commented:
LIKE %RIENTRATO RIPARATO%
is not what you are after, this will give you all records having these 2 words in it, in the same order, not either one


  SQL.Text :=
    'select * from riparazioni where cliente = :cliente  '+
       'and ( StatoAssistenza = :stato1 '+
       '   or StatoAssistenza = :stato2 )'+
       'and accettazioneanno = :anno';
     Params.ParamByName('CLIENTE').AsString := combocliente.EditingText;
     Params.ParamByName('STATO1').AsString := 'RIENTRATO';
     Params.ParamByName('STATO2').AsString := 'RIPARATO';
     Params.ParamByName('ANNO').AsString := comboanno.Text;

Open in new window

Author

Commented:
This code works perfectly, thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial