[Solved] User input in Query independant of UCASE and LCASE

Discuss the database features
Post Reply
dreamquartz
Posts: 899
Joined: Mon May 30, 2011 4:02 am

[Solved] User input in Query independant of UCASE and LCASE

Post by dreamquartz »

Hello All,

Trying to figure out how to let a user put in date into a userinput without having them think about Upper or Lower Case.

See attached DataBase.
The QUERY

Code: Select all

SELECT
	 "Service" || IFNULL( ', ' || "TypeOfService", '' ) AS "Service",
	 IFNULL( "UnitPrice", NULL ) AS "UnitPrice"
 FROM
  "Service" LEFT OUTER JOIN "TypeOfService" ON "Service"."FKTypeOfServiceID" = "TypeOfService"."TypeOfServiceID"
 WHERE
	 "Service" LIKE '%' || :Service || '%' AND
	 ( "TypeOfService" LIKE '%' || :TypeOfService || '%' OR "TypeOfService" IS NULL )
(thanks to F3K Total)

If a user is trying to select a 'Service' and puts in 'service', nothing is found.

I would like a situation where both inputs are acceptable.

Any thoughts?

Dream
Attachments
ServiceTypeOfService-2.odb
(5.14 KiB) Downloaded 207 times
Last edited by dreamquartz on Tue Mar 25, 2014 5:48 pm, edited 1 time in total.
LO 7.x, HSQLDB 2.7.x & Ubuntu 24.04 LTS.
F3K Total
Volunteer
Posts: 1046
Joined: Fri Dec 16, 2011 8:20 pm

Re: User input in Query independant of UCASE () and LCASE ()

Post by F3K Total »

What about thinking by yourself?

Code: Select all

SELECT
    "Service" || IFNULL( ', ' || "TypeOfService", '' ) AS "Service",
    IFNULL( "UnitPrice", NULL ) AS "UnitPrice"
FROM
  "Service" LEFT OUTER JOIN "TypeOfService" ON "Service"."FKTypeOfServiceID" = "TypeOfService"."TypeOfServiceID"
WHERE
    LOWER("Service") LIKE LOWER('%' || :Service || '%') AND
    ( LOWER("TypeOfService") LIKE LOWER('%' || :TypeOfService || '%' )OR "TypeOfService" IS NULL )
R
  • MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
  • my current system
  • Windows 11 AOO, LO | Linux Mint AOO, LO
dreamquartz
Posts: 899
Joined: Mon May 30, 2011 4:02 am

Re: User input in Query independant of UCASE () and LCASE ()

Post by dreamquartz »

F3K Total wrote:What about thinking by yourself?

Code: Select all

SELECT
    "Service" || IFNULL( ', ' || "TypeOfService", '' ) AS "Service",
    IFNULL( "UnitPrice", NULL ) AS "UnitPrice"
FROM
  "Service" LEFT OUTER JOIN "TypeOfService" ON "Service"."FKTypeOfServiceID" = "TypeOfService"."TypeOfServiceID"
WHERE
    LOWER("Service") LIKE LOWER('%' || :Service || '%') AND
    ( LOWER("TypeOfService") LIKE LOWER('%' || :TypeOfService || '%' )OR "TypeOfService" IS NULL )
R
I did think about it, and came up with

Code: Select all

WHERE
	 (LOWER ( "Service" ) LIKE '%' || :Service || '%' OR UPPER ( "Service" ) LIKE '%' || :Service || '%' OR ( "Service" ) LIKE '%' || :Service || '%' ) AND
	 (LOWER ( "TypeOfService" ) LIKE '%' || : TypeOfService || '%' OR UPPER ( "TypeOfService" ) LIKE '%' || : TypeOfService || '%' OR ( "TypeOfService" ) LIKE '%' || : TypeOfService || '%' OR "TypeOfService" IS NULL )
I did not have time to place my solution on the Forum.
I do like your solution better.
It is simpler and apprears to do the same thing.

Thanks for this,

Dream
LO 7.x, HSQLDB 2.7.x & Ubuntu 24.04 LTS.
F3K Total
Volunteer
Posts: 1046
Joined: Fri Dec 16, 2011 8:20 pm

Re: [SOLVED] User input in Query independant of UCASE and LC

Post by F3K Total »

Hi,
my query above

Code: Select all

    SELECT
        "Service" || IFNULL( ', ' || "TypeOfService", '' ) AS "Service",
        IFNULL( "UnitPrice", NULL ) AS "UnitPrice"
    FROM
      "Service" LEFT OUTER JOIN "TypeOfService" ON "Service"."FKTypeOfServiceID" = "TypeOfService"."TypeOfServiceID"
    WHERE
        LOWER("Service") LIKE LOWER('%' || :Service || '%') AND
        ( LOWER("TypeOfService") LIKE LOWER('%' || :TypeOfService || '%' )OR "TypeOfService" IS NULL )
should be improved for HSQL Version 1.8.0.10 ( Embedded dtaabase )

Thanks to Sliderule!
  1. With HSQL . . . per the documentation . . . both . . . HSQL 1.8 and 2.3 . . . Fred Tousi says, do NOT use IFNULL, but, use COALESCE instead.
  2. No reason to have a IFNULL ( or COALESCE ) on:

    Code: Select all

     IFNULL( "UnitPrice", NULL )
    since, it will return the same result, regardless if the value is NULL or NOT NULL.
  3. Column names are NOT fully qualified, with a column name of "Service" and a table name of "Service" . That is causing issues, as explained by Sliderule in prior post ( second post ) to dreamquartz.

    viewtopic.php?f=13&t=68372
  4. In order to use defined indexes ( indices ) and NOT to require extra coding ( lower or upper ) and when search is required from other queries, by changing ONCE, the column type from VARCHAR to VARCHAR_IGNORECASE . . . case ( UPPER, Mixed, lower ) is a non-issue. The two columns, can be 'edited' in the GUI ( Graphic User Interface ) for the tables ( right-click, edit ):

    Table: "Service" change from VARCHAR to VARCHAR_IGNORECASE
    Table: "TypeOfService" change from VARCHAR to VARCHAR_IGNORECASE
  5. Bottom line . . . the SQL should be:

    Code: Select all

    SELECT 
       "Service"."Service" || COALESCE( ', ' || "TypeOfService"."TypeOfService", '' ) AS "Service", 
       "Service"."UnitPrice" as "UnitPrice"
    
    FROM "Service" 
         LEFT OUTER JOIN "TypeOfService" ON "Service"."FKTypeOfServiceID" = "TypeOfService"."TypeOfServiceID" 
    
    WHERE "Service"."Service" LIKE '%' || :Service || '%' 
      AND ( "TypeOfService"."TypeOfService" LIKE '%' || :TypeOfService || '%' OR "TypeOfService"."TypeOfService" IS NULL )
R
  • MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
  • my current system
  • Windows 11 AOO, LO | Linux Mint AOO, LO
dreamquartz
Posts: 899
Joined: Mon May 30, 2011 4:02 am

Re: [Solved] User input in Query independant of UCASE and LC

Post by dreamquartz »

Hi F3K Total,

Thanks for that.
I did read about the COALESCE instead of ISNULL, but did not try it in the past, because we wanted to restrict the way the data was stored in both the Service as the TypeOfService tables.
It is not that difficult to set up guidelines on how items should be entered, next to the use of i.e. MASKS, and ListBoxes.

I did follow your advise at this point, because of the described potential issues with ISNULL.

At this point we have not renamed all the tables, forms and queries yet, but they will be.
Services will become tblServices, Forms will start with 'frm, and Queries will start with 'qry'. At this point it is just saving the typing.

Dream.
LO 7.x, HSQLDB 2.7.x & Ubuntu 24.04 LTS.
Post Reply