SQL query with IS LIKE clause - and user entry

Creating tables and queries
Post Reply
Got_LibreOffice
Posts: 9
Joined: Fri Dec 09, 2022 4:06 am

SQL query with IS LIKE clause - and user entry

Post by Got_LibreOffice »

Hello,
I'm new to OO_Base so I may be barking up the wrong tree.
But I would like to create a form which has a search field in it.
I would type in a search string and it would initiate a search based on a pre-made query

That query would have one WHERE clause which will be an IS LIKE clause - the string of which the user must enter at run time.

So for example - I would be searching a column in a table where some text within that table IS LIKE whatever the user enters at run-time.

I think I'm headed in the correct path in accomplishing this.
If so - then what I would be asking here is the Query Syntax for the IS LIKE clause requiring user entry at run-time

Sincere thanks in advance!
OpenOffice Version: 6.2.8.2 - on Linux Lite
User avatar
robleyd
Moderator
Posts: 5087
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: SQL query with IS LIKE clause - and user entry

Post by robleyd »

Did you look at [Solved] Way to pass parameters into queries?

You don't mention which database you are using - Base is not a database but an interface to a number of database applications - but I don't know of any variant of SQL that has IS LIKE; there is LIKE however.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
Got_LibreOffice
Posts: 9
Joined: Fri Dec 09, 2022 4:06 am

Re: SQL query with IS LIKE clause - and user entry

Post by Got_LibreOffice »

Sorry
That was my mistake
The DB is one created within OO_Base
So LIKE would be correct
Thanks
OpenOffice Version: 6.2.8.2 - on Linux Lite
F3K Total
Volunteer
Posts: 1039
Joined: Fri Dec 16, 2011 8:20 pm

Re: SQL query with IS LIKE clause - and user entry

Post by F3K Total »

Hello,
two samples:
1. with parameter

Code: Select all

... WHERE ( LOWER ( "Name" ) LIKE LOWER ( :qName || '%' ) OR :qNameIS NULL )
2. using an extra filtertable

Code: Select all

... WHERE ( LOWER ( "Name" ) LIKE LOWER ( (SELECT "F_Name" FROM "Filter") || '%' ) OR (SELECT "F_Name" FROM "Filter") NULL )
Info:

Code: Select all

|| '%'
means, you have only to type the beginning of a word to match all words that begin like what you typed in.
  • MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
  • my current system
  • Windows 10 AOO, LOLinux Mint AOO, LO
Got_LibreOffice
Posts: 9
Joined: Fri Dec 09, 2022 4:06 am

Re: SQL query with IS LIKE clause - and user entry

Post by Got_LibreOffice »

I'm having trouble getting the system to take the query with the input parameter function included.

The field being queried contains sentences.
I am essentially looking for any sentence which includes a search string anywhere within the sentence
So if I am looking for sentences which contain the word "nothing" the following query works:

SELECT "Person", "Category", "Quote" FROM "tblQuotes" WHERE "Quote" LIKE '*nothing*'

But when I try to change the fixed string "nothing" to an input parameter - the system indicates the query is "to complex"

SELECT "Person", "Category", "Quote" FROM "tblQuotes" WHERE "Quote" LIKE '%' || :SearchString || '%'
OpenOffice Version: 6.2.8.2 - on Linux Lite
F3K Total
Volunteer
Posts: 1039
Joined: Fri Dec 16, 2011 8:20 pm

Re: SQL query with IS LIKE clause - and user entry

Post by F3K Total »

i wonder, just tested your query, worked for me, using HSQLDB and FIREBIRD also.
  • MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
  • my current system
  • Windows 10 AOO, LOLinux Mint AOO, LO
Got_LibreOffice
Posts: 9
Joined: Fri Dec 09, 2022 4:06 am

Re: SQL query with IS LIKE clause - and user entry

Post by Got_LibreOffice »

F3K Total wrote: Sun Dec 11, 2022 6:52 pm i wonder, just tested your query, worked for me, using HSQLDB and FIREBIRD also.
Thanks!
I wonder if there is a difference in required syntax between OO_Base versions?
OpenOffice Version: 6.2.8.2 - on Linux Lite
Got_LibreOffice
Posts: 9
Joined: Fri Dec 09, 2022 4:06 am

Re: SQL query with IS LIKE clause - and user entry

Post by Got_LibreOffice »

Got_LibreOffice wrote: Sun Dec 11, 2022 9:06 pm
F3K Total wrote: Sun Dec 11, 2022 6:52 pm i wonder, just tested your query, worked for me, using HSQLDB and FIREBIRD also.
Thanks!
I wonder if there is a difference in required syntax between OO_Base versions?
I just discovered there is a difference between Open Office and LibreOffice.
I am not using Open Office - I have LibreOffice
Even so - when I read the LibreOffice documentation of adding wildcards to parameters it shows the system I've tried which the system does not like.
OpenOffice Version: 6.2.8.2 - on Linux Lite
UnklDonald418
Volunteer
Posts: 1549
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: SQL query with IS LIKE clause - and user entry

Post by UnklDonald418 »

Instead of a parameter you could use a Filter Table.
Demo40A_FilterTable.odb
(24.66 KiB) Downloaded 202 times
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: SQL query with IS LIKE clause - and user entry

Post by Villeroy »

Combine parameter query and filter table if the filtered row set needs to be editable.
Attachments
Demo40A_FilterTable2.odb
(25.58 KiB) Downloaded 205 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Mountaineer
Posts: 318
Joined: Sun Sep 06, 2020 8:27 am

Re: SQL query with IS LIKE clause - and user entry

Post by Mountaineer »

Got_LibreOffice wrote: Sat Dec 10, 2022 5:06 pm ...
The DB is one created within OO_Base
...
Maybe you created a "datasource" not a database.
A source can also be a dbase-file (like the default bilbliography), a spreadsheet or even csv-Files. These are limited, and give often "to complex" as error.

The there a 2 types of databases "included", the default HSQLDB and Firebird. You find YOUR type in the lower status-bar of the database-window.
OpenOffice 3.1 on Windows Vista
Mountaineer
Posts: 318
Joined: Sun Sep 06, 2020 8:27 am

Re: SQL query with IS LIKE clause - and user entry

Post by Mountaineer »

Got_LibreOffice wrote: Sun Dec 11, 2022 10:38 pm ...
I just discovered there is a difference between Open Office and LibreOffice.
I am not using Open Office - I have LibreOffice
Even so - when I read the LibreOffice documentation of adding wildcards to parameters it shows the system I've tried which the system does not like.
Main point: SQL does use % as a wildcard instead of the * of the file-systems.

Difference between OO and LO is quite neglectable concerning Base. LO has integrated the report-builde extension and delivers also Firebase.
OpenOffice 3.1 on Windows Vista
Post Reply