1

I am having trouble with below ADOQuery quoted string %ABC%:

adoQuery1.SQL.Clear;
adoQuery1.SQL.Text := 'SELECT * FROM MyDB.MyTable WHERE MyField LIKE ''''%ABC%'''' ';
adoQuery1.ExecSQL;
adoQuery1.Close;
adoQuery1.Open;

I also tried to pass below parameter instead but no success:

adoQuery1.SQL.Clear;
adoQuery1.SQL.Text := 'SELECT * FROM MyDB.MyTable WHERE MyField LIKE :Param1 ';
aqBCCombi.Parameters.ParamByName('Param1').Value := '%ABC%';
adoQuery1.ExecSQL;
adoQuery1.Close;
adoQuery1.Open;

Here's the error I get: Parameter object is improperly defined. Inconsistent or incomplete information was provided.

Anyone here who knows how to handle quoted string within the ADO SQL text? Appreciate any help.

2
  • 1
    FYI, ExecSQL; Close; Open; makes absolutely no sense. Second, use Open for SELECT - ExecSQL is for queries that do not return a resultset (insert, delete, update). Commented Jun 2, 2021 at 1:03
  • Noted @KenWhite . Thanks for the advise. Commented Jun 2, 2021 at 4:20

1 Answer 1

1

This code very similar to yours works for me:

if Pos('%', Article) > 0 then begin
    SQLCmd := 'SELECT d0301000.id_partstd ' +
              'FROM d0301000 ' +
              'WHERE (d0301000.Type = ''AF'') ' +
                'AND (d0301000.Part_Nbr LIKE :Part_Nbr)';
    ADOQuery1.SQL.Text := SQLCmd;
    ADOQuery1.Parameters.ParamByName('Part_Nbr').Value := Article;
end
else begin 
    .....   // Code removed for simplicity
end;
ADOQuery1.Open;

You are using ExecSQL for a SELECT statement. Replace it with Open.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.