Is it possible to put a wildcard search into a parameter input query in Base?

I am using Base in LibreOffice 4.0 (still using the HSQL that comes with Base but looking at moving to HSQL 2.2.8) and I would like to do a query that asks for parameter input like:

SELECT * FROM “Contacts” WHERE “FirstName” LIKE :FirstName and when you run the query a window pops up asking for your parameter input for ‘FirstName’

The problem with this one is that my current client is, well, a terrible speller, and the Parameter input requires an exact match, including capitals.

I tried multiple ways to add the wildcard % symbol to the parameter search and it will not work.

I used SQL to make a wildcard query ( eg SELECT * FROM “Contacts” WHERE “FirstName” LIKE ‘W%’ ) but unfortunately it requires this client going into the SQL for that query and changing the letters he is searching for, and again this is not an option for my client who is also not proficient in SQL, databases, or computers for that matter.

Is there any way to put a wild card search into a query that produces a parameter input? OR is there some macro I can program (help please!) that will do this for me?

Note: While the search record box does search for the match anywhere in the field this is a very slow search method due to the large number of contacts. My attempt to use an INDEX to speed the search was also unsuccessful (see my other question regarding this here: Is there a way to create Indexes that will actually speed up record searches in LibreOffice Base?

This version:

SELECT * FROM “Contacts” WHERE LOWER(“FirstName”) LIKE LOWER(’%’ || :FirstName || ‘%’)

changes your query as follows:

  • it does a case-insensitive comparison, by converting to lowercase before doing the comparison
  • it works even if you insert part of the value to be searched, because it surrounds the user-entered value with ‘%’

Be careful with this, at least in LO 5.0.2. It seems to insist on spaces before and after the quoted percent signs for some reason (LO bug?). I found that LIKE LOWER ( ‘%’ || :FirstName || ‘%’ ) works OK. Without the spaces it thinks that the whole thing is a string, encloses it in single quotes and adds an “=” at the front: ‘LIKE LOWER( ‘’%’’ || :FirstName || ‘’%’’)’ Bizarre.

Why don’t you just make a FORM with a drop-down list (using a list box) where your client could just choose the name (and simply typing in the first letter would also take you to the right section of the drop-down list).