SQL Commands in Delphi 1

SQL Commands in Delphi 1

Post by Andrew Bennet » Fri, 23 May 1997 04:00:00



Hope this is the correct group to post this message.
I have a problem using the LIKE command in a SQL command to find part of a
string in a string field. Using LIKE with a defined string containing the
whole of the string to look for works OK but cannot get it to find part of
string, as shown below. I cannot find any info in the Delphi Help or
manuals for this command but have used it in Visual Basic OK.

If the asterisks (which I believe are the wildcard characters) are removed
VS180 is found OK but not with them. I need to be able to enter a partial
string and locate the whole.

procedure TformManuals.Button1Click(Sender: TObject);
var tofind : string;
begin
tofind := '"*VS180*"';    
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('SELECT * FROM MANUALS');
Query1.SQL.Add('WHERE Model LIKE' + tofind +'');
Query1.Open;
end;

Thanks in advance,
Andy.

 
 
 

SQL Commands in Delphi 1

Post by Marc Scheun » Sat, 24 May 1997 04:00:00



>Hope this is the correct group to post this message.
>I have a problem using the LIKE command in a SQL command to find part of a
>string in a string field.
>If the asterisks (which I believe are the wildcard characters) are removed
>VS180 is found OK but not with them. I need to be able to enter a partial
>string and locate the whole.

Well, the asterisk and quotation mark are the DOS wildcards, but not
the SQL........

Use % and _ instead. The % (percent) stands for any number of
characters (like the *), the _ (underscore) for exactly one character
(like the ? ).

So if you would use
 select * from table where stringval like '%VS180%'

then it would find what you're looking for.

Marc

======================================================================

======================================================================