× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi James,

Searches for 01, 02, 03, and 04 would all hit, but so would searches for 10, 20, and 30. Is there a practical way to prevent the spurious hits, other than to bite the bullet and allow space for delimiters?

With or without spaces, the way you're doing it is not a great idea. Why? Because it's going to require a full table scan -- there's no way to build an index to improve search times.

The "right" way to do this is to have your codes stored in a separate table, one record per code. That way, you can join the tables, and have indexes on the fields to improve performance.

But let's assume you don't want to do that, and that there are only a small number of records, so a full table scan doesn't matter to you...

a) You could use SUBSTR.

select blah,blah from mytable
where substr(field1,1,2)='01'
or substr(field1,3,2)='01'
or substr(field1,5,2)='01'
or substr(field1,7,2)='01'
or substr(field1,9,2)='01'


b) Since the above SUBSTR is cumbersome. You could write a UDF. The UDF would receive the field containing the list, and the code(s) to look for as parameters. It would then return whether it was found or not.

select blah,blah from mytable
where MYUDF(field1,'01')=1


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.