Reputation: 639
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.
Upvotes: 1
Views: 283
Reputation: 12292
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
.
Upvotes: 1