Gianluca
Gianluca

Reputation: 990

Ignore Case sql query

I am trying to basically ignore the case sensitivity for my db2 sql select * query, so that I can populate the products to my catalogue page. Ex. If I type in my search bar 'squeege', I want the item 'Squeege' to populate, even if there is a difference in Upper/lower case. What is the best way to do this, based on the code I have below?

var searchProduct = "select * from LISTOFPRODUCTS where ITEM LIKE  '%" + searchValue + "%'" 

Thanks in advance for the help :)

Upvotes: 0

Views: 106

Answers (3)

Paul Vernon
Paul Vernon

Reputation: 3901

You can also consider using REGEXP_LIKE which has a case-insensitive option i

Upvotes: 1

J.F.
J.F.

Reputation: 15187

I think this could work:

var searchProduct = "select * from LISTOFPRODUCTS where UPPER(ITEM) LIKE  UPPER('%" + searchValue + "%'")

Also the same with LOWER()

Note that the trick is parse both values to UPPER() or LOWER() to match them.

Upvotes: 3

sourheart
sourheart

Reputation: 124

You can use the function LOWER(). For example:

var searchProduct = "select * from LISTOFPRODUCTS where LOWER(ITEM) LIKE  '%" + searchValue + "%'" 

Upvotes: 1

Related Questions