SQL Query using TEdit.text lazarus / 16-Databases ---------------------------------------------------------------------- soymoe · 2019-01-18 22:20 I need to make a query of a database that contains the code '%' and the text of an edit, something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i begin     if(RadioButtonCUIT.Checked)then          begin          ZQueryBusqueda.Close;          ZQueryBusqueda.sql.Clear;          ZQueryBusqueda.sql.Add('SELECT * FROM personas WHERE CUIL/CUIT LIKE'+'%'+EditBusqueda.Text);          ZQueryBusqueda.Open;          end;      if(RadioButtonAPELLIDO.Checked)then          begin          ZQueryBusqueda.Close;          ZQueryBusqueda.sql.Clear;          ZQueryBusqueda.sql.Add('SELECT*FROM personas WHERE APELLIDO LIKE '+'%'+EditBusqueda.Text);          ZQueryBusqueda.Open;          end;end; ---------------------------------------------------------------------- daveinhull · 2019-01-18 22:42 Not sure if you can put '/' in the WHERE clause of the first SQL and what error do you get? ---------------------------------------------------------------------- soymoe · 2019-01-18 22:48 The field is called CUIL / CUIT, the error is sql logic error ---------------------------------------------------------------------- daveinhull · 2019-01-18 23:02 Do you need to put a space in between the end of LIKE and the start %? I think the string ends up as SELECT * FROM personas WHERE CUIL/CUIT LIKE%< what ever is in here EditBusqueda.Text> ---------------------------------------------------------------------- soymoe · 2019-01-19 19:09 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TFormLlamador.EditBusquedaChange(Sender: TObject);begin     if(RadioButtonCUIT.Checked)then          begin          ZQueryBusqueda.Close;          ZQueryBusqueda.sql.Clear;          ZQueryBusqueda.sql.Add('SELECT * FROM personas WHERE CUIL/CUIT LIKE '+ QuotedStr('%' + EditBusqueda.Text));          ZQueryBusqueda.Open;        end;     if(RadioButtonAPELLIDO.Checked)then          begin        ZQueryBusqueda.Close;          ZQueryBusqueda.sql.Clear;          ZQueryBusqueda.sql.Add('SELECT * FROM personas WHERE APELLIDO LIKE '+ QuotedStr('%' + EditBusqueda.Text));          ZQueryBusqueda.Open;        end;end;                                   The first sentence does not work, the second one does ---------------------------------------------------------------------- GAN · 2019-01-19 20:17 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TFormLlamador.EditBusquedaChange(Sender: TObject);begin     if (RadioButtonCUIT.Checked) then          begin          ZQueryBusqueda.Close;          ZQueryBusqueda.sql.Text:='SELECT * FROM personas WHERE (CUIL LIKE ''%'+EditBusqueda.Text+'%'') OR (CUIT LIKE ''%'+EditBusqueda.Text+'%'')';          ZQueryBusqueda.Open;          end;     if(RadioButtonAPELLIDO.Checked)then          begin          ZQueryBusqueda.Close;          ZQueryBusqueda.sql.Text:='SELECT * FROM personas WHERE APELLIDO LIKE '+ QuotedStr('%' + EditBusqueda.Text);        ZQueryBusqueda.Open;          end;end; Hi Moe, try this and if you want post this in the spanish forum. I'm argentine too and know about CUIT, CUIL etc. ---------------------------------------------------------------------- madref · 2019-01-19 22:37 Put it between [ ] and it should work Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ZQueryBusqueda.sql.Add('SELECT * FROM personas WHERE [CUIL/CUIT] LIKE '+ QuotedStr('%' + EditBusqueda.Text + '%'));or this is what i do Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i sa := 'CD_Artiest LIKE ' + CHR(39) + '%' + txt_Artiest.Text + '%' + CHR(39); ---------------------------------------------------------------------- soymoe · 2019-01-19 22:44 IT  WORK THANKS! ---------------------------------------------------------------------- madref · 2019-01-20 02:09 Can you also give the solution for future reference. So that other people also know how to recreate it? ---------------------------------------------------------------------- soymoe · 2019-01-20 02:12 this is the solution: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TFormLlamador.EditBusquedaChange(Sender: TObject);begin     if(RadioButtonCUIT.Checked)then          begin          ZQueryBusqueda.Close;          ZQueryBusqueda.sql.Clear;          ZQueryBusqueda.sql.Add('SELECT * FROM personas WHERE [CUIL/CUIT] LIKE '+ QuotedStr(EditBusqueda.Text+'%'));          ZQueryBusqueda.Open;        end;     if(RadioButtonAPELLIDO.Checked)then          begin        ZQueryBusqueda.Close;          ZQueryBusqueda.sql.Clear;          ZQueryBusqueda.sql.Add('SELECT * FROM personas WHERE APELLIDO LIKE '+ QuotedStr(EditBusqueda.Text+'%'));          ZQueryBusqueda.Open;        end;end; ---------------------------------------------------------------------- ASerge · 2019-01-20 05:46 It is strange that nobody suggested to use the parameters. It is faster and safer and does not contain the difficulties mentioned here. ---------------------------------------------------------------------- Zoran · 2019-01-20 06:00 Quote from: ASerge on January 20, 2019, 06:46:57 amIt is strange that nobody suggested to use the parameters. It is faster and safer and does not contain the difficulties mentioned here. I don't think that you can use parameters in LIKE. ---------------------------------------------------------------------- ASerge · 2019-01-20 06:16 Quote from: Zoran on January 20, 2019, 07:00:34 amI don't think that you can use parameters in LIKE. In which database? ---------------------------------------------------------------------- Zoran · 2019-01-20 21:49 Quote from: ASerge on January 20, 2019, 07:16:38 amQuote from: Zoran on January 20, 2019, 07:00:34 amI don't think that you can use parameters in LIKE. In which database? Actually I was wrong, now I tried and it works (Firebird).