0

I am trying to execute a simple select*from statement with delphi but cannot get it to work. Please assist.

With Data.personel Do
 Begin
   Active:=False;
   Sql.Text:='Select*From personel where (name like ''%'+Combobox1.Text+'%'') and (surname like ''%'+Combobox2.Text+'%'') and (id_number like ''%'+Combobox3.Text+'%'') sort by '+sortfield1+','+sortfield2+','+sortfield3;
   Active:=True;
 End;

Sortfield1,2,3 are just variables that change when the sort comboboxes are changed.

I keep getting the same error, that there is a missing operator. I cannot figure out what is wrong. any assistance would be great, thanks.

user3271392
  • 149
  • 2
  • 12

2 Answers2

2
With Data.personel Do
  Begin
    Active:=False;
    Sql.Text:='Select * From personel where ' +
              '(name like '          + QuotedStr('%' + Combobox1.Text+'%')   + ') ' +
              'and (surname like '   + QuotedStr('%' + Combobox2.Text +'%')  + ') ' +
              'and (id_number like ' + QuotedStr('%' + Combobox3.Text + '%') + ') ' +
              'order by ' + sortfield1 + ',' +
                            sortfield2 + ',' +
                            sortfield3;
    Active:=True;
  End;
pedro.olimpio
  • 1,478
  • 2
  • 22
  • 43
1
With Data.personel Do
 Begin
   Active:=False;
   Sql.Text:='Select*From personel where (name like ''%'+Combobox1.Text+'%'') and (surname like ''%'+Combobox2.Text+'%'') and (id_number like ''%'+Combobox3.Text+'%'') Order by '+sortfield1+','+sortfield2+','+sortfield3;
   Active:=True;
 End;

"Order by", not "Sort By".

Stupid mistake but very hard to see if not looking for it

user3271392
  • 149
  • 2
  • 12