Board index » delphi » Search records for partial matches

Search records for partial matches

I need to search a Table for records that have certain text strings in
them.  I can't seem to get it right.  Here is what I'm trying to do:

If I search for "oh", I need to have "Doh!" and "oh" both show up in
the search.

 I used to do this with VB something like this:

 (findcrit is text to be found (i.e. "oh") in each record)

DBName.RecordSource = "SELECT * FROM Query " & " WHERE " & findcrit

Can someone show this data on a grid, with Delphi 2.0?  

 

Re:Search records for partial matches


In article <322f71eb.183332...@news.seanet.com>, From
bry...@bryand.seanet.com, the following was written:

Quote
> I need to search a Table for records that have certain text strings in
> them.  I can't seem to get it right.  Here is what I'm trying to do:

> If I search for "oh", I need to have "Doh!" and "oh" both show up in
> the search.

> I used to do this with VB something like this:

> (findcrit is text to be found (i.e. "oh") in each record)

> DBName.RecordSource = "SELECT * FROM Query " & " WHERE " & findcrit

> Can someone show this data on a grid, with Delphi 2.0?  

You will need a TDBGrid component, TQuery component, and a TDataSource
component.  Tie the DataSource to the TQuery via the DataSet Property.
Tie the DBGRid to the Datasource via the datasource property.  Then in
the SQL property of the TQuery add:

Select * from MyTable where (Field1 Like "%oh%") or (Field2 Like "%oh%")

TQuery1.Open;    {will run the query}

God Bless,

--
Jay Schwisow j...@weldnet.com
09/05/96 22:54
---------
Using: OUI PRO 1.5.0.2 from http://www.dvorak.com

Re:Search records for partial matches


Try
'select * from table where field like "%' + findcrit + '%"'

Nick Spurrier (MoDESoft, UK)

Re:Search records for partial matches


On Fri, 06 Sep 1996 00:43:27 GMT,

Quote
bry...@bryand.seanet.com  <bry...@bryand.seanet.com> wrote:
>If I search for "oh", I need to have "Doh!" and "oh" both show up in
>the search.

How about: SELECT * FROM MyTable WHERE MyColumn LIKE '%oh%'

Lito

Lito Dizon
adi...@us.net

Other Threads