Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1955
  • Last Modified:

Upper and lowercase in a query

Hello,
I have a table where the users may enter names in upper and/or lowercase. I could have, for example, NAME1 equal to 'ABEL MARY' and NAME2 equal to 'deBlank John'. The query in the code does the following:

select count(*) from table
where upper(name) >= :NAME1
and upper(name) <= :NAME2

but that is obviously resulting in a restricted data set and it does not covers the lowercase names. Considering that the user may type either NAME1 and/or NAME2 with upper or lowercases, how would it be the best way to cover all the data range in the table?
thanks

0
hcarvajal
Asked:
hcarvajal
1 Solution
 
NickUpsonCommented:
the usual way is to add an additional field to the table, called, say UPPERNAME

populate it with triggers that contain

new.UPPERNAME = UPPER(name)

then always do your search against UPPERNAME

there are other ways, such as using specific character sets and collations but this is the simplest

this way the database doesn't need to convert every record to uppercase everytime the query is run
0
 
Gary BenadeCommented:
select count(*) from table
where upper(name) >= upper(:NAME1)
and upper(name) <= upper(:NAME2)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now