Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Query - improve speed using LIKE

Status
Not open for further replies.

Anesthaesia

Technical User
Aug 30, 2001
126
GB
Hi,

I have read through some posts about table scans in SQL, which are performed when using a LIKE query.

Is there any other way to do this and improve performance?

I am currently using ...AND rsRec LIKE '%" & txtSearch.text & "%'... in the query.

I need to be able to do a wildcard search, but was hoping there may be a better way.

Cheers,
D
 
Well, if you can, you should restrict your search variable to use only one wildcard on one side. However, I understand the need to possibly use two wildcards.

The next thing to do is to full-text index the field you are searching on with the wildcards (i.e. rsRec).

Take Care,
Mike
 
Thanks Mike,

That's something I had a look at but wasn't sure about (not too familiar with SQL indexing/performance)

Going to give it a try now...

Cheers,
D
 
Indexes on text fields are built based on the left-to-right ordering of the characters in the field so a LIKE clause of the form
Code:
[myField] LIKE 'ABC%'
can use the index.

Any search involving a prefix wildcard such as
Code:
[myField] LIKE '%ABC%'
cannot because it must examine each field searching for "ABC" somewhere in the field (not necessarily at the start of the field)

As Mike says, some systems support full-text indexing and that can substantially improve text search performance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top