Subject Re: [firebird-support] use of 'LIKE %'
Author Jason Dodson
I do not think it is NECESSARILY bad practice, though, when using
'like', even if the field is indexed, the index won't be used.

You could possibly consider having the condition change the SQL to:

"... Where Status = :ItemStatus"

When it is ANYTHING BUT 'All', and simply omit the Where clause if 'All'
is chosen.


Vahan Yoghoudjian wrote:
> Hi group
> I have a table containing stock item definitions where items have a
> status (of type char(1)) to be differentiated. In the application the user
> can decide what type of items to see according to values stored in a combo
> box. Let's say the choices in the combo box are:
> -All - %
> -Products - P
> -Services - S
> -Bundles - B
> -etc...
> When the data in the combo is changed I use the following query to fetch the
> item records
> Select field1, field2,field3 from Items where Status LIKE :ItemStatus
> The reason I use 'LIKE' and not '=' is to have a dynamic query for every
> value selected from the combo and whenever the 'All' item is selected to use
> the same query with the % key.
> Is this a bad habit? Would it be better to change 'where status like
> :ItemStatus' to 'where status = :ItemStatus' and omit this condition part
> when all items have to be fetched or Firebird ignores conditions like 'LIKE
> %' since all records have to be fetched anyway?
> Thanks in advance
> Vahan