
Signature
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
I tried changing the wildcard characters and it didn't recognise them so I
had to change them back.
I have an Access database with a table called "product". I want to create a
query that uses this. The SQL that Access gives me for the query I am trying
to create is this:
SELECT [Product Table].ProdID, [Product Table].Supplier, [Product
Table].Descr, [Product Table].CustomerPrice
FROM [Product Table]
WHERE ((([Product Table].Descr) Like "*clock*"))
ORDER BY [Product Table].ProdID;
But I want to use this through Delphi. To do this, I have to use an ADO
query. I don't know if this is possible as the Access help says this:
"The Microsoft Jet database engine uses the Microsoft® Visual Basic® for
Applications (or VBA) expression service to perform simple arithmetic and
function evaluation. All of the operators used in Microsoft Jet SQL
expressions (except Between , In , and Like ) are defined by the VBA
expression service."
So it may be that the Like operator for Access SQL cannot be used in Delphi.
But the code I am trying to write to do this is this:
begin
ADOQryDescr.close;
ADOQryDescr.Parameters[1].Value := edtDescr.Text;
with ADOQryDescr.SQL do
begin
clear;
add('SELECT [Product Table].ProdID, [Product Table].Supplier,
[Product Table].Descr, [Product Table].CustomerPrice FROM [Product Table]');
add('WHERE (([Product Table].Descr Like "* (:descr)*")');
add('ORDER BY [Product Table].ProdID;');
end;
ADOQryDescr.Active:=true;
ADOQryDescr.Open;
end;
(I am passing the text using a parameter, descr, which is defined correctly)
And it doesn't work, so I don't know if it's a problem with my code, or with
Delphi not being able to use the Like operator, or what, and whether or not
there is another operator I can use instead? Thank you!
Dirk Goldgar - 11 Feb 2005 16:42 GMT
(comments inline)
> I tried changing the wildcard characters and it didn't recognise them
> so I had to change them back.
[quoted text clipped - 18 lines]
> So it may be that the Like operator for Access SQL cannot be used in
> Delphi.
No, that's just saying that the Between, In, and Like operators are
defined by Jet SQL, not by the VBA expression service, so you *can* use
them in non-Access queries.
> But the code I am trying to write to do this is this:
>
[quoted text clipped - 18 lines]
> or what, and whether or not there is another operator I can use
> instead? Thank you!
My guess is that your parameter is not being recognized as such inside
the literal string pattern "* (:descr)*". You could approach this one
of two ways. You might try breaking the pattern up into concatenated
pieces within the SQL, like this:
add('WHERE (([Product Table].Descr Like "*"+(:descr)+"*")');
Or, since you know the value of the parameter [descr] at the time you
are buildiong the SQL, just drop the parameter altogether and build that
value right into the SQL. I'm not conversant with Delphi, but I guess
it might look something like this:
------- start of code -- probably not exactly correct -------
begin
ADOQryDescr.close;
with ADOQryDescr.SQL do
begin
clear;
add('SELECT [Product Table].ProdID, [Product
Table].Supplier,
[Product Table].Descr, [Product Table].CustomerPrice FROM [Product
Table]');
add('WHERE (([Product Table].Descr Like
"*'+edtDescr.Text+'*")');
add('ORDER BY [Product Table].ProdID;');
end;
ADOQryDescr.Active:=true;
ADOQryDescr.Open;
end;
(more code here)
------- end of code -------

Signature
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)